#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  int _s, _c, i = 0;
  while (cin >> _s >> _c) {
    s[i] = _s;
    c[i] = _c;
    i++;
  }
  int n_start, n_end;
  if (N == 1) {
    n_start = 0;
    n_end = 9;
  } else if (N == 2) {
    n_start = 10;
    n_end = 99;
  } else if (N == 3) {
    n_start = 100;
    n_end = 999;
  }
  int digit1, digit2, digit3;
  int answer;
  if (M > 0) {
    answer = -1;
  } else {
    answer = n_start;
  }
  for (int n = n_start; n <= n_end; n++) {
    digit1 = floor(n / 100.0);
    digit2 = floor((n - 100.0 * digit1) / 10.0);
    digit3 = floor(n - 100.0 * digit1 - 10.0 * digit2);
    for (int j = 0; j < 3; j++) {
      if (digit1 == 0) {
        digit1 = digit2;
        digit2 = digit3;
        digit3 = -1;
      }
    }
    int OK = 0;
    for (int i = 0; i < M; i++) {
      if (s[i] == 1 && digit1 == c[i]) {
        OK++;
      } else if (s[i] == 2 && digit2 == c[i]) {
        OK++;
      } else if (s[i] == 3 && digit3 == c[i]) {
        OK++;
      }
    }
    if (OK == M) {
      answer = n;
      break;
    }
  }
  cout << answer << endl;
  return 0;
}
