#include <bits/stdc++.h>
using namespace std;
int cnt_digits(long long X) {
  int cnt = 0;
  while (X > 0) {
    X /= 10;
    cnt++;
  }
  return cnt;
}
int cn(int x, int y) {
  string t = to_string(x);
  return t[y - 1] - '0';
}
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < (m); ++i) cin >> s[i] >> c[i];
  for (int i = 0; i <= 999; i++) {
    if (cnt_digits(i) != n) continue;
    bool ok = true;
    for (int j = 0; j < (m); ++j) {
      if (cn(i, s[j]) != c[j]) ok = false;
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
