#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, m;
  cin >> n >> m;
  vector<long> a(4);
  long s, c;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (a[s] != 0) {
      if (a[s] != c) {
        cout << "-1" << endl;
        return 0;
      }
    } else {
      a[s] = c;
    }
  }
  long res;
  res = a[1] * 100 + a[2] * 10 + a[3];
  if (res != 0) {
    cout << a[1] * 100 + a[2] * 10 + a[3] << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
