#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  long long low, high;
  if (n == 1) low = 0, high = 9;
  if (n == 2) low = 10, high = 99;
  if (n == 3) low = 100, high = 1000;
  long long a[2 * m];
  for (long long i = 0; i < 2 * m; i++) cin >> a[i];
  for (low = 0; low < high; low++) {
    long long x = low;
    string s;
    while (x) {
      long long k = x % 10;
      x /= 10;
      char c = '0' + k;
      s += c;
    }
    reverse(s.begin(), s.end());
    bool ok = true;
    for (long long i = 0; i < 2 * m; i += 2) {
      long long x = a[i];
      x--;
      long long k = a[i + 1];
      char c = '0' + k;
      if (c != s[x]) {
        ok = false;
        break;
      }
    }
    if (s.size() > 1 && s[0] == '0') ok = false;
    if (ok) {
      cout << low << "\n";
      return;
    }
  }
  cout << -1 << "\n";
  return;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  solve();
  return 0;
}
