#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M;
  cin >> N >> M;
  long long a = 1;
  long long s, c;
  long long i, j;
  bool flag;
  for (i = pow(10, N - 1); i < pow(10, N); i++) {
    for (j = 0; j < M; j++) {
      cin >> s >> c;
      flag = true;
      if (i % (long long)pow((long long)10, N - s + 1) /
              pow((long long)10, N - s) !=
          c) {
        flag = false;
      }
      if (flag) {
        cout << i;
        return 0;
      }
    }
  }
  cout << -1;
  return 0;
}
