#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
  int n, m, keta, l;
  string a;
  bool flag;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < (m); ++i) cin >> s[i] >> c[i];
  for (int x = 0; x < 1000; x++) {
    keta = 0;
    l = x;
    flag = true;
    while (l != 0) {
      keta++;
      l /= 10;
    }
    if (keta != n) continue;
    a = to_string(x);
    for (int i = 0; i < (a.size()); ++i) {
      if (a[s[i] - 1] != c[i]) flag = false;
    }
    if (flag) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
