#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
bool is_int_lround(double x) { return std::lround(x) == x; }
int ketasuu(int x) {
  int n = 0;
  while (x > 0) {
    x /= 10;
    n++;
  }
  return n;
}
ll conbi(int n, int m) {
  cin >> n >> m;
  vector<ll> a(100);
  a[0] = 1;
  for (int i = 0; i < 14; i++) {
    a[i + 1] = a[i] * (i + 1);
  }
  return a[n] / (a[m] * a[n - m]);
}
int main() {
  int n, m;
  cin >> n >> m;
  vi s(m);
  vector<char> c(m);
  ;
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  int keta = 9;
  while (n - 1) {
    keta = keta * 10 + 9;
    n--;
  }
  bool ok = true;
  for (int i = keta / 10 + 1; i <= keta; i++) {
    string suu = to_string(i);
    ok = true;
    for (int j = 0; j < m; j++) {
      if (suu[s[j] - 1] != c[j]) {
        ok = false;
      }
    }
    if (ok) {
      cout << i << endl;
      break;
    }
  }
  if (!ok) cout << -1 << endl;
}
