#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
bool solve(int s, int c, int n) {
  int tmp = n;
  tmp = tmp / (pow(10, 3 - s)) - (int)(tmp / pow(10, 4 - s)) * 10;
  return tmp == c;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > p(m);
  for (int i = 0; i < (m); i++) {
    cin >> p[i].first >> p[i].second;
  }
  int ans = -1;
  if (n == 1) {
    for (int i = 0; i < 10; i++) {
      bool ok = true;
      for (int j = 0; j < (m); j++) {
        if (!solve(p[j].first, p[j].second, i)) {
          ok = false;
          break;
        }
      }
      if (ok) {
        ans = i;
        break;
      }
    }
  } else if (n == 2) {
    for (int i = 10; i < 100; i++) {
      bool ok = true;
      for (int j = 0; j < (m); j++) {
        if (!solve(p[j].first, p[j].second, i)) {
          ok = false;
          break;
        }
      }
      if (ok) {
        ans = i;
        break;
      }
    }
  } else {
    for (int i = 100; i < 1000; i++) {
      bool ok = true;
      for (int j = 0; j < (m); j++) {
        if (!solve(p[j].first, p[j].second, i)) {
          ok = false;
          break;
        }
      }
      if (ok) {
        ans = i;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
