#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long N, M;
  cin >> N >> M;
  long long a[2 * 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 = 999;
  for (long long i = 0; i < 2 * M; i++) cin >> a[i];
  for (; low <= high; low++) {
    long long x = low;
    string s;
    while (x) {
      long long z = x % 10;
      char c = z - '0';
      s += c;
      x /= 10;
    }
    reverse(s.begin(), s.end());
    bool ok = true;
    for (long long i = 0; i < 2 * M; i += 2) {
      long long t = a[i] - 1;
      long long chk = a[i + 1];
      char ch = chk - '0';
      if (s[t] != ch) {
        ok = false;
        break;
      }
    }
    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;
}
