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