#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = (1 << 28);
const long long infl = (1LL << 60);
int digit(int x) {
  int d = 0;
  while (x > 0) {
    d++;
    x /= 10;
  }
  return d;
}
int nth_digit(int x, int n) {
  int d = digit(x) - n;
  if (d < 0) return -1;
  int res = (x / (int)pow(10, d)) % 10;
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  for (int i = 0; i < (m); ++i) {
    cin >> s[i] >> c[i];
  }
  for (int x = 1; x < 1000; x++) {
    if (digit(x) != n) continue;
    bool flag = true;
    for (int i = 0; i < m; i++) {
      if (nth_digit(x, s[i]) != c[i]) flag = false;
    }
    if (flag) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
