#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  pair<int, int> p[5];
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> p[i].first >> p[i].second;
  }
  for (int i = 0; i < 1000; i++) {
    if (floor(log10(i) + 1) == n) {
      for (int j = 0; j < m; j++) {
        if (to_string(i)[p[j].first - 1] != p[j].second + '0') {
          j = m;
        }
        if (j == m - 1) {
          cout << i << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1";
  return 0;
}
