#include <bits/stdc++.h>
using namespace std;
long long keta(long long x) {
  for (long long i = 0; i < 30; i++) {
    if (x < 10) {
      return i + 1;
    }
    x = x / 10;
  }
}
long long gcd(long long x, long long y) {
  long long aa = x, bb = y;
  for (long long i = 0; i < 1000; i++) {
    aa = aa % bb;
    if (aa == 0) {
      return bb;
    }
    bb = bb % aa;
    if (bb == 0) {
      return aa;
    }
  }
}
long long lcm(long long x, long long y) {
  long long aa = x, bb = y;
  for (long long i = 0; i < 1000; i++) {
    aa = aa % bb;
    if (aa == 0) {
      return x / bb * y;
    }
    bb = bb % aa;
    if (bb == 0) {
      return x / aa * y;
    }
  }
}
bool p(long long x) {
  if (x == 1) return false;
  for (long long i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0 && x != i) {
      return false;
    }
  }
  return true;
}
long long n2[41];
long long nis[41];
long long nia[41];
long long mody[41];
long long nn;
long long com(long long n, long long y) {
  long long ni = 1;
  for (long long i = 0; i < 41; i++) {
    n2[i] = ni;
    ni *= 2;
  }
  long long bunsi = 1, bunbo = 1;
  for (long long i = 0; i < y; i++) bunsi = (bunsi * (n - i)) % 1000000007;
  for (long long i = 0; i < y; i++) bunbo = (bunbo * (i + 1)) % 1000000007;
  mody[0] = bunbo;
  nis[0]++;
  for (long long i = 0; i < 41; i++) {
    if (nis[i] == 1) {
      bunsi = (bunsi * mody[i]) % 1000000007;
    }
  }
  return bunsi;
}
long long a[114514], b[114514];
long long bin[9];
string ss[114514];
signed main() {
  long long m;
  cin >> m;
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i] >> b[i];
  long long ans = -1;
  if (m == 1) {
    for (long long i = 0; i < n; i++) {
      if (ans != -1 && ans != b[i]) {
        cout << -1 << endl;
        return 0;
      }
      if (a[i] == 1) ans = b[i];
    }
    cout << ans << endl;
    return 0;
  }
  long long ans1 = -1;
  long long ans2 = -1;
  if (m == 2) {
    for (long long i = 0; i < n; i++) {
      if (a[i] == 1 && ans1 != -1 && ans1 != b[i]) {
        cout << -1 << endl;
        return 0;
      }
      if (a[i] == 2 && ans2 != -1 && ans2 != b[i]) {
        cout << -1 << endl;
        return 0;
      }
      if (a[i] == 1) ans1 = b[i];
      if (a[i] == 2) ans2 = b[i];
    }
    if (ans1 == -1) ans1 = 1;
    if (ans2 == -1) ans2 = 0;
    cout << ans1 * 10 + ans2 << endl;
  }
  ans1 = -1;
  ans2 = -1;
  long long ans3 = -1;
  if (m == 3) {
    for (long long i = 0; i < n; i++) {
      if (a[i] == 1 && ans1 != -1 && ans1 != b[i]) {
        cout << -1 << endl;
        return 0;
      }
      if (a[i] == 2 && ans2 != -1 && ans2 != b[i]) {
        cout << -1 << endl;
        return 0;
      }
      if (a[i] == 3 && ans3 != -1 && ans2 != b[i]) {
        cout << -1 << endl;
        return 0;
      }
      if (a[i] == 1) ans1 = b[i];
      if (a[i] == 2) ans2 = b[i];
      if (a[i] == 3) ans3 = b[i];
    }
    if (ans1 == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (ans1 == -1) ans1 = 1;
    if (ans2 == -1) ans2 = 0;
    if (ans3 == -1) ans3 = 0;
    cout << ans1 * 100 + ans2 * 10 + ans3 << endl;
  }
}
