#include <bits/stdc++.h>
using namespace std;
int guess_number(int N, int M) {
  int s[3], c[9];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i <= 999; i++) {
    bool is_valid_number = true;
    int first = i % 10;
    int second = (i % 100) / 10;
    int third = (i % 1000) / 100;
    for (int j = 0; j < M; j++) {
      if ((s[j] == 1 && third == c[j]) || (s[j] == 2 && second == c[j]) ||
          (s[j] == 3 && first == c[j])) {
        continue;
      } else {
        is_valid_number = false;
        break;
      }
    }
    if (is_valid_number) {
      int temp = i, count = 0;
      while (temp > 0) {
        count++;
        temp /= 10;
      }
      if (count == N) return i;
    }
  }
  return -1;
}
int main() {
  int N, M;
  cin >> N >> M;
  cout << guess_number(N, M) << endl;
  return 0;
}
