#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < (int)(M); i++) cin >> s.at(i) >> c.at(i);
  vector<int> num(N, -1);
  bool ok = true;
  for (int i = 0; i < (int)(M); i++) {
    if (num.at(s.at(i) - 1) == -1) {
      num.at(s.at(i) - 1) = c.at(i);
    } else if (num.at(s.at(i) - 1) == c.at(i)) {
      num.at(s.at(i) - 1) = c.at(i);
    } else {
      ok = false;
      break;
    }
  }
  if (num.at(0) == 0) {
    ok = false;
  }
  int ans = 0;
  if (ok) {
    if (N == 1 && (num.at(0) == -1 || num.at(0) == 0)) {
      ans = 0;
    } else {
      if (num.at(0) == -1) {
        num.at(0) = 1;
      }
      for (int i = 0; i < (int)(N); i++) {
        if (num.at(i) == -1) {
          num.at(i) = 0;
        }
      }
      for (int i = 0; i < (int)(N); i++) {
        ans += num.at(i) * pow(10, N - 1 - i);
      }
    }
  } else {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}
