#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int r[3][10] = {};
  for (int i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    r[s - 1][c] = 1;
  }
  for (int i = 0; i < 3; ++i) {
    bool bFound = false;
    int j = 0;
    for (j = 0; j < 10; ++j) {
      if (r[i][j]) {
        bFound = true;
        break;
      }
    }
    if (bFound == false) {
      j = 0;
    }
    if (i == 0 && j == 0) {
      printf("-1\n");
      return 0;
    }
    printf("%d", j);
  }
  printf("\n");
  return 0;
}
