#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(m);
  vector<int> q(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> p[i] >> q[i];
  }
  if (n == 1)
    for (int i = 1; i < (int)(10); i++) {
      bool ome = true;
      for (int j = 0; j < (int)(m); j++) {
        if (i != q[j]) ome = false;
      }
      if (ome) {
        cout << i << endl;
        return 0;
      }
      if (i == 9) cout << -1 << endl;
    }
  if (n == 2)
    for (int i = 10; i < 100; i++) {
      bool ome = true;
      for (int j = 0; j < (int)(m); j++) {
        if ((p[j] == 1 && i / 10 != q[j]) || (p[j] == 2 && i % 10 != q[j]))
          ome = false;
      }
      if (ome) {
        cout << i << endl;
        return 0;
      }
      if (i == 99) cout << -1 << endl;
    }
  if (n == 3)
    for (int i = 100; i < 1000; i++) {
      bool ome = true;
      for (int j = 0; j < (int)(m); j++) {
        if ((p[j] == 1 && i / 100 != q[j]) ||
            (p[j] == 2 && (i / 10) % 10 != q[j]) ||
            (p[j] == 3 && i % 10 != q[j]))
          ome = false;
      }
      if (ome) {
        cout << i << endl;
        return 0;
      }
      if (i == 999) cout << -1 << endl;
    }
}
