#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int* s = new int[m];
  int* c = new int[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int o = pow(10, n);
  int answer = -1;
  bool flag;
  for (int i = 0; i < 1000; i++) {
    flag = true;
    for (int j = 0; j < m; j++) {
      int a;
      switch (s[j]) {
        case 1:
          if (c[j] != (int)(i / 100)) {
            flag = false;
          }
          break;
        case 2:
          if (c[j] != ((int)(i / 10) % 10)) {
            flag = false;
          }
          break;
        case 3:
          if (c[j] != i % 10) {
            flag = false;
          }
          break;
        default:
          break;
      }
    }
    if (flag) {
      answer = i;
    }
    if ((answer * 10 / o) <= 0) {
      answer = -1;
    }
    if (answer >= o) {
      answer = -1;
    }
    if (answer != -1) {
      break;
    }
  }
  cout << answer;
  return 0;
}
