#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  vector<int> c(n, -1);
  for (int i = 0; i < (int)(m); i++) {
    int ss, cc;
    cin >> ss >> cc;
    if (ss == 1 && cc == 0 && n != 1) {
      cout << -1 << endl;
      return 0;
    }
    if (c[ss - 1] != -1 && cc != c[ss - 1]) {
      cout << -1 << endl;
      return 0;
    }
    c[ss - 1] = cc;
  }
  int ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    if (i == 0 && c[i] == -1) {
      c[i] = 1;
    } else if (i > 0 && c[i] == -1) {
      c[i] = 0;
    }
    ans += pow(10, n - 1 - i) * c[i];
  }
  cout << ans << endl;
}
