#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 < (1000); i++) {
    f = true;
    if (i <= 9) {
      for (long long j = 0; j < (m); j++) {
        if (s[j] == 1) {
          if (c[j] != (i % 10)) {
            f = false;
            break;
          }
        } else {
          f = false;
          break;
        }
      }
    } else if (i <= 99) {
      for (long long j = 0; j < (m); j++) {
        if (s[j] == 1) {
          if (c[j] != (i / 10)) {
            f = false;
            break;
          }
        } else if (s[j] == 2) {
          if (c[j] != (i % 10)) {
            f = false;
            break;
          }
        } else {
          f = false;
          break;
        }
      }
    } else {
      for (long long j = 0; j < (m); j++) {
        if (s[j] == 1) {
          if (c[j] != (i / 100)) {
            f = false;
            break;
          }
        } else if (s[j] == 2) {
          if (c[j] != (i / 10)) {
            f = false;
            break;
          }
        } else if (s[j] == 3) {
          if (c[j] != (i % 10)) {
            f = false;
            break;
          }
        }
      }
    }
    if (f) {
      if (i == 0 && n != 1) {
        continue;
      } else {
        ans = i;
        break;
      }
    }
  }
  if (f)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
