#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
const intl INF = 1e9;
const intl MOD = 1e9 + 7;
const ld eps = 1.0e-14;
void fp(bool flag) {
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
void fp(bool flag, string s, string t) {
  if (flag)
    cout << s << endl;
  else
    cout << t << endl;
}
intl kai(intl k) {
  intl a = 1;
  for (intl i = 2; i <= k; i++) {
    a *= i;
  }
  return a;
}
intl gcd(intl a, intl b) {
  if (!b) return a;
  return gcd(b, a % b);
}
intl digit10(intl a) {
  intl b = 0;
  while (a) {
    a /= 10;
    b++;
  }
  return b;
}
signed main() {
  cout << fixed << setprecision(10);
  intl n, m;
  cin >> n >> m;
  intl s[m], c[m];
  for (intl i = 0; i < (intl)(m); i++) {
    cin >> s[i] >> c[i];
  }
  intl ans = -1;
  for (intl i = 0; i < (intl)(1000); i++) {
    bool flag = true;
    intl d = digit10(i);
    if (n != d) continue;
    intl a[3];
    memset(a, -1, sizeof(a));
    intl b = i;
    for (intl j = 0; j < (intl)(d); j++) {
      a[2 - j] = (b % 10);
      b /= 10;
    }
    for (intl j = 0; j < (intl)(m); j++) {
      if (a[s[j] - 1] != c[j]) flag = false;
    }
    if (flag) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
