#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) {
    int si, ci;
    cin >> si >> ci;
    si = n - si;
    s.at(i) = si;
    c.at(i) = ci;
  }
  for (int i = 0; i <= 999; ++i) {
    vector<int> x;
    int t = i;
    while (t > 0) {
      x.push_back(t % 10);
      t /= 10;
    }
    if (x.size() == n) {
      bool ok = true;
      for (int j = 0; j < m; ++j) {
        if (x.at(s.at(j)) != c.at(j)) {
          ok = false;
          break;
        }
      }
      if (ok) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
