#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(3);
  vec = {0, 0, 0};
  int s, c;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (vec.at(s - 1) == 0) {
      vec.at(s - 1) = c;
    } else if (vec.at(s - 1) == c) {
      continue;
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (N == 2 && vec.at(1) == 0) {
    cout << "-1" << endl;
    return 0;
  } else if (N == 3 && vec.at(0) == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < 3; i++) {
    cout << vec.at(i);
  }
}
