#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long a, long long m) { return (a % m + m) % m; }
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int n, m, a[5], c[5];
int d[3];
void solve() {
  cin >> n >> m;
  fill(d, d + 3, -1);
  bool ok = 1;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> c[i];
    a[i]--;
    if (d[a[i]] != -1 && d[a[i]] != c[i]) {
      ok = 0;
    }
    d[a[i]] = c[i];
  }
  if (!ok) {
    cout << -1 << endl;
    return;
  }
  if (n == 1) {
    if (d[0] == -1)
      cout << 0 << endl;
    else
      cout << d[0] << endl;
  }
  if (n == 2) {
    for (int i = 10; i < 100; i++) {
      if ((d[1] == -1 || i % 10 == d[1]) && (d[0] == -1 || (i / 10) == d[0])) {
        cout << i << endl;
        return;
      }
    }
  }
  for (int i = 100; i < 1000; i++) {
    if ((d[2] == -1 || i % 10 == d[2]) &&
        (d[1] == -1 || (i % 100) / 10 == d[1]) &&
        (d[0] == -1 || (i / 100) == d[0])) {
      cout << i << endl;
      return;
    }
  }
  cout << -1 << endl;
}
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
