#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[3] = {-1, -1, -1};
  int n, m, s, c;
  bool ac = true;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (a[s - 1] == -1 || a[s - 1] == c)
      a[s - 1] = c;
    else
      ac = false;
  }
  if (n > 1 && a[3 - n] == 0) {
    ac = false;
  }
  if (n > 1 && a[3 - n] == -1) {
    a[3 - n] = 1;
  }
  if (ac) {
    for (int i = 3 - n; i < 3; i++) {
      cout << ((a[i] == -1) ? 0 : a[i]);
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  cin >> n;
  return 0;
}
