#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
int main() {
  int n, m;
  int s, c;
  vector<int> sv, cv;
  cin >> n >> m;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> c;
    sv.push_back(s);
    cv.push_back(c);
  }
  int ans = 0;
  int table[n];
  for (int i = 0; i < 1000; i++) {
    int t = i;
    for (int j = 0; j < (int)(n); j++) {
      table[j] = -1;
    }
    for (int j = 0; j < (int)(n); j++) {
      table[j] = t % 10;
      t /= 10;
      if (t == 0) break;
    }
    for (int j = 0; j < (int)(m); j++) {
      if (cv[j] != table[(n - sv[j])]) {
        break;
      }
      if (j == m - 1) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
