#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 < (m); i++) {
    cin >> s[i] >> c[i];
  }
  int ans = 0;
  vector<int> num(n, -1);
  for (int i = 0; i < (m); i++) {
    if (num[s[i] - 1] == -1) {
      num[s[i] - 1] = c[i];
    }
    if (num[s[i] - 1] != c[i]) {
      ans = -1;
      break;
    }
  }
  if (n == 1 && ans == 0) {
    if (num[0] == -1) {
      ans = 0;
    } else {
      ans = num[0];
    }
  } else if (ans == 0) {
    for (int i = 0; i < (n); i++) {
      if (num[i] == -1) {
        if (i == 0) {
          num[i] = 1;
        } else {
          num[i] = 0;
        }
      }
    }
    ans = 0;
    for (int i = 0; i < (n); i++) {
      ans += pow(10, n - i - 1) * num[i];
    }
  }
  cout << ans << endl;
  return 0;
}
