#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = -1, x, keta = 0;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < (int)(pow(10, n)); i++) {
    x = i / 10;
    keta = 1;
    while (x >= 1) {
      x /= 10;
      keta++;
    }
    if (keta == n) {
      for (int j = 0; j < (int)(m); j++) {
        if (i != 0 && int((i / (pow(10, n - s[j])))) % 10 != c[j]) {
          break;
        } else if (i == 0 && i != c[j]) {
          break;
        } else if (j == m - 1) {
          ans = i;
        }
      }
    }
    if (ans != -1) {
      break;
    }
  }
  cout << ans << endl;
}
