#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, M;
  cin >> N >> M;
  ll s[5], c[5];
  for (ll(i) = (0), i_len = (M); (i) < (i_len); ++(i)) {
    cin >> s[i] >> c[i];
    --s[i];
  }
  ll K = 1;
  for (ll(i) = (1), i_len = (N); (i) < (i_len); ++(i)) K *= 10;
  ll num = -1;
  ll d[3];
  bool f;
  f = true;
  for (ll(i) = (0), i_len = (M); (i) < (i_len); ++(i)) {
    if (N != 1 && s[i] == 0 && c[i] == 0) {
      f = false;
      break;
    }
  }
  if (f && N == 1) {
    for (ll(i) = (0), i_len = (M); (i) < (i_len); ++(i)) {
      if (s[i] == 0 && c[i] != 0) {
        f = false;
        break;
      }
    }
    if (f) num = 0;
  } else if (f) {
    for (ll(i) = (K), i_len = (1000); (i) < (i_len); ++(i)) {
      d[0] = i / 100;
      d[1] = (i / 10) % 10;
      d[2] = i % 10;
      f = true;
      for (ll(j) = (0), j_len = (M); (j) < (j_len); ++(j)) {
        for (ll(k) = (0), k_len = (3); (k) < (k_len); ++(k)) {
          if (s[j] == k && c[j] != d[k]) {
            f = false;
            break;
          }
        }
      }
      if (f) {
        num = i;
        break;
      }
    }
  }
  cout << (num) << endl;
  return 0;
}
