#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int(i) = 0; (i) < (m); (i)++) {
    cin >> s.at(i) >> c.at(i);
  }
  int ans = -1;
  for (int(i) = 0; (i) < (1000); (i)++) {
    {
      int keta = 0;
      int now = i;
      while (now > 0) {
        now /= 10;
        keta++;
      }
      if (keta != n) continue;
    }
    {
      string now = to_string(i);
      bool check = true;
      for (int(j) = 0; (j) < (m); (j)++) {
        int keta = s.at(j) - 1;
        if ((now.at(keta) - '0') != c.at(j)) {
          check = false;
          continue;
        }
      }
      if (!check) continue;
    }
    ans = i;
    break;
  }
  cout << ans;
}
