#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int ju = 1;
  cin >> N >> M;
  vector<int> ans(N, 0);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s == 0 && c == 0) {
      ju = 0;
      break;
    }
    if (ans.at(s) == 0) {
      ans.at(s) = c;
    } else if (ans.at(s) != c) {
      ju = 0;
      break;
    }
  }
  if (!ju) {
    cout << -1;
  } else {
    for (int i = 0; i < N; i++) {
      cout << ans.at(i);
    }
  }
  cout << endl;
}
