#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  int res = -1;
  int hajimari;
  int owari;
  if (N == 1) {
    hajimari = 0;
    owari = 9;
  } else if (N == 2) {
    hajimari = 10;
    owari = 99;
  } else if (N == 3) {
    hajimari = 100;
    owari = 999;
  }
  for (int i = hajimari; i <= owari; i++) {
    bool ok = true;
    int d = i / 100, b = (i / 10) % 10, a = i % 10;
    for (int j = 0; j < M; j++) {
      if (s[j] == 1 && c[j] == 0) {
        ok = false;
      } else if (i < 100 && s[j] == 2 && c[j] == 0) {
        ok = false;
      } else if (s[j] == 1 && c[j] == d) {
        continue;
      } else if (s[j] == 2 && c[j] == b) {
        continue;
      } else if (s[j] == 3 && c[j] == a) {
        continue;
      } else {
        ok = false;
      }
    }
    if (ok) {
      res = i;
      break;
    }
  }
  cout << res << endl;
}
