#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main() {
  int n, m, s, c;
  int a[3];
  fill(a, a + 3, -1);
  cin >> n >> m;
  if (m == 0) {
    cout << 0 << endl;
    return 0;
  }
  while (m--) {
    cin >> s >> c;
    if (a[s - 1] >= 0 && a[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    a[s - 1] = c;
  }
  for (int i = pow(10, n - 1); i < pow(10, n); ++i) {
    string v = to_string(i);
    for (int j = 0; j < n; ++j) {
      if (v[j] - '0' != a[j]) break;
      if (j == n - 1) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
