#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int ans = -1;
  for (int i = 0; i < 1000; i++) {
    if (i / pow(10, n - 1) == 0 && !(n == 1 && i == 0)) {
      continue;
    }
    bool flag = true;
    for (int j = 0; j < m; j++) {
      if ((int)(i / pow(10, n - s[j])) % 10 != c[j]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans = i;
      break;
    }
  }
  for (int j = 0; j < m; j++) {
    if (n >= 2 && (s[j] == 1 && c[j] == 0)) {
      ans = -1;
    }
  }
  cout << ans << endl;
  return 0;
}
