#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
int main() {
  int N = 0, M;
  cin >> N >> M;
  vector<int> S(N, -1);
  bool can = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (S[s - 1] == -1 || S[s - 1] == c) {
      S[s - 1] = c;
    } else {
      can = false;
    }
  }
  int keta = 2;
  for (int i = 0; i < N; i++) {
    if (S[i] != -1) keta = min(keta, i);
  }
  if (keta < 2 && S[0] == 0) can = false;
  if (can) {
    for (int i = keta; i < 3; i++) {
      cout << max(S[i], 0);
    }
  } else {
    cout << -1;
  }
  return 0;
}
