#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (int)(m); i++) cin >> s[i] >> c[i];
  for (int x = 0; x < (int)(1000); x++) {
    int nx = x / 10;
    int digit = 1;
    vector<int> d(n);
    d[0] = x % 10;
    while (nx) {
      digit++;
      int i = 1;
      d[i] = nx % 10;
      nx /= 10;
      i++;
    }
    if (n != digit) continue;
    reverse(d.begin(), d.end());
    bool ex = true;
    for (int j = 0; j < (int)(m); j++) {
      if (d[s[j] - 1] != c[j]) ex = false;
    }
    if (ex == true) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
