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