#include <bits/stdc++.h>
using namespace std;
int main() {
  long long(n), (m);
  scanf("%lld%lld", &(n), &(m));
  ;
  map<int, int> mapa;
  long long low, high;
  if (n == 1) low = 0, high = 9;
  if (n == 2) low = 10, high = 99;
  if (n == 3) low = 100, high = 999;
  for (long long i = 0; i < (m); i++) {
    long long(s), (c);
    scanf("%lld%lld", &(s), &(c));
    ;
    s = 5 - (s + n - 1);
    if (mapa.count(s) && mapa[s] != c) {
      printf("-1\n");
      return 0;
    }
    mapa[s] = c;
  }
  for (long long i = low; i <= high; i++) {
    bool f = 0;
    vector<long long> a{i % 10, i / 10 % 10, i / 100 % 10, i / 1000 % 10,
                        i / 10000 % 10};
    for (auto i : mapa) {
      if (a[i.first] != i.second) f = 1;
    }
    if (f) continue;
    printf("%lld\n", i);
    return 0;
  }
  printf("-1\n");
  return 0;
}
