#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, j, a = 0;
  cin >> N >> M;
  int s[M], c[M];
  for (int l = 0; l < M; l++) {
    cin >> s[l] >> c[l];
  }
  if (N == 1) {
    for (int i = 0; i < 10; i++) {
      j = M;
      for (int k = 0; k < M; k++) {
        if (c[k] == i) {
          j--;
        }
      }
      if (j == 0) {
        cout << i << endl;
        a = 1;
        break;
      }
    }
  }
  if (N == 2) {
    for (int i = 10; i < 100; i++) {
      j = M;
      for (int k = 0; k < M; k++) {
        if ((s[k] == 1 && c[k] == i / 10) ||
            (s[k] == 2 && c[k] == i - (i / 10) * 10)) {
          j--;
        }
      }
      if (j == 0) {
        cout << i << endl;
        a = 1;
        break;
      }
    }
  }
  if (N == 3) {
    for (int i = 100; i < 1000; i++) {
      j = M;
      for (int k = 0; k < M; k++) {
        if ((s[k] == 1 && c[k] == i / 100) ||
            (s[k] == 2 && c[k] == (i - (i / 100) * 10) / 10) ||
            (s[k] == 3 && c[k] == i - (i / 10) * 10)) {
          j--;
        }
      }
      if (j == 0) {
        cout << i << endl;
        a = 1;
        break;
      }
    }
  }
  if (a != 1) {
    cout << -1 << endl;
  }
}
