#include <bits/stdc++.h>
using namespace std;
const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;
const double PI = acos(-1);
long long dx[] = {0, 0, -1, 1, -1, -1, 1, 1};
long long dy[] = {1, -1, 0, 0, 1, -1, -1, 1};
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  a %= b;
  return gcd(b, a);
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > v(m);
  for (int i = 0; i < m; i++) {
    cin >> v[i].first >> v[i].second;
  }
  if (n == 1) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < m; j++) {
        if (v[j].second == i) {
          cout << i << '\n';
          return;
        }
      }
    }
  } else if (n == 2) {
    for (int i = 10; i < 100; i++) {
      int num1 = i;
      int num2 = num1 % 10;
      num1 /= 10;
      int ok = 1;
      for (int j = 0; j < m; ++j) {
        if (v[j].first == 1 and v[j].second == num1) {
          continue;
        }
        if (v[j].first == 2 and v[j].second == num2) {
          continue;
        }
        ok = 0;
      }
      if (ok) {
        cout << i << '\n';
        return;
      }
    }
  } else if (n == 3) {
    for (int i = 100; i < 1000; i++) {
      int num1 = i;
      int num3 = num1 % 10;
      num1 /= 10;
      int num2 = num1 % 10;
      num1 /= 10;
      int ok = 1;
      for (int j = 0; j < m; ++j) {
        if (v[j].first == 1 and v[j].second == num1) {
          continue;
        }
        if (v[j].first == 2 and v[j].second == num2) {
          continue;
        }
        if (v[j].first == 3 and v[j].second == num3) {
          continue;
        }
        ok = 0;
      }
      if (ok) {
        cout << i << '\n';
        return;
      }
    }
  }
  cout << -1 << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
