#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 = 9; i >= 0; i--) {
    a[0] = i;
    for (int j = 9; j >= 0; j--) {
      if ((j > 0) && (n < 2)) continue;
      a[1] = j;
      for (int k = 9; k >= 0; k--) {
        if ((k > 0) && (n < 3)) continue;
        a[2] = k;
        for (int l = 0; l < m; l++) {
          if (a[n - s[l]] != c[l]) can = false;
          if ((a[n - 1] == 0) && (n != 1)) can = false;
        }
        if (can) ans = k * 100 + j * 10 + i;
        can = true;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
