#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(N, -1);
  for (int i = 0; i < M; i++) {
    int k, c;
    cin >> k >> c;
    if (s[N - k] != -1 && s[N - k] != c) {
      cout << -1 << endl;
      return 0;
    }
    s[N - k] = c;
  }
  for (int i = 1; i < 10000; i++) {
    int i_ = i;
    bool ok = true;
    for (int j = 0; j < N; j++) {
      if (i_ % 10 != s[j]) ok = false;
      i_ /= 10;
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
}
