#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int a[3], n, m, s[5], c[5], ans = -1;
  cin >> n >> m;
  bool can = true;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < 10; i++) {
    a[0] = i;
    for (int j = 0; j < 10; j++) {
      a[1] = j;
      if (n < 2) a[1] = 0;
      for (int k = 0; k < 10; k++) {
        a[2] = k;
        if (n < 3) a[2] = 0;
        for (int l = 0; l < m; l++) {
          if (a[n - s[l]] != c[l]) can = false;
          if ((c[l] == 0) && ((n - s[l]) > 1)) can = false;
        }
        if (can) ans = k * 100 + j * 10 + i;
        can = true;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
