#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int s[5], c[5];
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
  }
  if (n != 1) {
    for (int i = 0; i < m; ++i) {
      if ((s[i] == 1) && (c[i] == 0)) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  char number[4];
  for (int i = 0; i < 1000; ++i) {
    sprintf(number, "%d", i);
    int j;
    for (j = 0; j < m; ++j) {
      if (number[s[j] - 1] != (48 + c[j])) {
        break;
      }
    }
    if (j == m) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
