#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(N, 0);
  vector<bool> valid(N, false);
  int s, c;
  bool x = true;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if ((valid.at(s - 1) && (vec.at(s - 1) != c)) || (s == 1 && c == 0)) {
      x = false;
      break;
    } else {
      vec.at(s - 1) = c;
      valid.at(s - 1) = true;
    }
  }
  if (x) {
    cout << (vec.at(0) == 0 ? 1 : vec.at(0)) << vec.at(1) << vec.at(2) << endl;
  } else {
    cout << -1 << endl;
  }
}
