#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n, m, arr[1000] = {0}, tmp, tmp2, tmp3, tmp4;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> tmp >> tmp2;
    if (tmp == 1 && tmp2 == 0) {
      if (n != 1) arr[0] = 1;
      for (int j = 1; j <= 999; ++j) arr[j] = 1;
    } else {
      for (int j = 0; j <= 999; ++j) {
        tmp4 = j;
        tmp3 = tmp;
        while (n != tmp3) {
          tmp4 /= 10;
          tmp3++;
        }
        if (tmp4 % 10 != tmp2) arr[j] = 1;
      }
    }
  }
  tmp = 0;
  if (arr[0] == 0) {
    cout << 0 << '\n';
    tmp = 1;
  } else {
    for (int i = 1; i <= 999; ++i) {
      int cnt = 0;
      tmp2 = i;
      while (tmp2) {
        tmp2 /= 10;
        cnt++;
      }
      if (cnt == n && !arr[i]) {
        tmp = 1;
        cout << i << '\n';
        break;
      }
    }
  }
  if (!tmp) cout << -1 << '\n';
  return 0;
}
