#include <bits/stdc++.h>
using namespace std;
string sm = "";
int a[6], b[6];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
  }
  int o = 1;
  for (int i = 0; i < n; i++) {
    o *= 10;
  }
  for (int i = o / 10; i < o; i++) {
    int u = 1;
    for (int c = 10; c <= i; c *= 10) {
      u = c / 10;
      int t = i % c;
      t /= u;
      char p = t + 48;
      sm.push_back(p);
    }
    for (int x = 0; x < m; x++) {
      int y = sm[a[x]] - 48;
      if (y == b[i]) {
        continue;
      }
    }
    reverse(sm.begin(), sm.end());
    if (sm[0] == '0') {
      continue;
    }
    cout << sm;
    return 0;
  }
  cout << "-1";
  return 0;
}
