#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m][2];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> s[i][j];
    }
  }
  int result = -1;
  if (n == 1) {
    int loop = 0;
    for (int i = 9; i >= 1; i--) {
      for (int j = 0; j < m; j++) {
        if (i == s[j][1]) {
          loop = 0;
          continue;
        } else {
          loop = 1;
          break;
        }
      }
      if (loop == 1)
        continue;
      else
        result = i;
    }
  } else if (n == 2) {
    int loop = 0;
    for (int i = 99; i >= 10; i--) {
      for (int j = 0; j < m; j++) {
        if (s[j][0] == 1 && s[j][1] == i / 10) {
          loop = 0;
          continue;
        } else if (s[j][0] == 2 && s[j][1] == i % 10) {
          loop = 0;
          continue;
        } else {
          loop = 1;
          break;
        }
      }
      if (loop == 1)
        continue;
      else
        result = i;
    }
  } else if (n == 3) {
    int loop = 0;
    for (int i = 999; i >= 100; i--) {
      for (int j = 0; j < m; j++) {
        if (s[j][0] == 1 && s[j][1] == i / 100) {
          loop = 0;
          continue;
        } else if (s[j][0] == 2 && s[j][1] == i / 10 % 10) {
          loop = 0;
          continue;
        } else if (s[j][0] == 3 && s[j][1] == i % 10) {
          loop = 0;
          continue;
        } else {
          loop = 1;
          break;
        }
      }
      if (loop == 1)
        continue;
      else
        result = i;
    }
  }
  cout << result << endl;
}
