#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long mod9 = 1000000009;
signed main() {
  long long n;
  long long m;
  cin >> n >> m;
  long long s[5];
  long long c[5];
  for (long long i = 0; i < (m); i++) cin >> s[i] >> c[i];
  long long ans;
  bool f = false;
  for (long long i = 0; i < (1001); i++) {
    f = true;
    if (i <= 9) {
      for (long long j = 0; j < (m); j++) {
        if (s[j] != 1 || c[j] != i) {
          f = false;
          continue;
        }
      }
    } else if (i < 99) {
      for (long long j = 0; j < (m); j++) {
        if (s[j] == 1) {
          if (c[j] != (i / 10)) {
            f = false;
            continue;
          }
        } else if (s[j] == 2) {
          if (c[j] != (i % 10)) {
            f = false;
            continue;
          }
        } else {
          f = false;
          continue;
        }
      }
    } else {
      for (long long j = 0; j < (m); j++) {
        if (s[j] == 1) {
          if (c[j] != (i / 100)) {
            f = false;
            continue;
          }
        } else if (s[j] == 2) {
          if (c[j] != (i / 10)) {
            f = false;
            continue;
          }
        } else if (s[j] == 3) {
          if (c[j] != (i % 10)) {
            f = false;
            continue;
          }
        } else {
          f = false;
          continue;
        }
      }
    }
    if (f) {
      ans = i;
      break;
    }
  }
  if (f) {
    if (ans == 0) {
      if (n == 1)
        cout << ans << endl;
      else
        cout << -1 << endl;
    } else
      cout << ans << endl;
  } else
    cout << -1 << endl;
}
