#include <bits/stdc++.h>
using namespace std;
int pow2(int n) { return int(pow(10, n) + 0.1); }
int main() {
  int N, M, *s, *c, *r, result = -1, flag, temp;
  int i, j, k;
  bool res;
  cin >> N >> M;
  s = new int[M];
  c = new int[M];
  r = new int[N];
  for (i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    r[i] = 0;
  }
  if (N > 1) {
    for (i = pow2(N - 1); i < pow2(N); i++) {
      temp = i;
      for (j = 0; j < N; j++) {
        r[j] = temp / pow2(N - j - 1);
        temp -= pow2(N - j - 1) * r[j];
      }
      res = true;
      for (j = 0; j < M; j++) {
        if (r[s[j] - 1] != c[j]) res = false;
      }
      if (res) {
        result = i;
        break;
      }
    }
  } else {
    temp = c[0];
    for (i = 0; i < M; i++) {
      if (temp == c[i]) break;
    }
    result = temp;
  }
  cout << result;
}
