#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 < (m); i++) {
    cin >> s[i] >> c[i];
  }
  for (int x = 0; x < (1000); x++) {
    int nx = x / 10;
    vector<int> d(1, x % 10);
    while (nx) {
      d.push_back(nx % 10);
      nx /= 10;
    }
    reverse(d.begin(), d.end());
    if (d.size() != n) continue;
    bool ok = false;
    for (int i = 0; i < (m); i++) {
      if (d[s[i] - 1] != c[i]) ok = false;
    }
    if (ok) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
