#include <bits/stdc++.h>
using namespace std;
bool check(int i, int n, int s, int c) {
  int x[3] = {1, 10, 100};
  if (n > 1 && i < x[n - 1]) return false;
  int cc = (i / x[n - s]) % 10;
  if (cc != c) return false;
  return true;
}
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  int c[m];
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < 1000; ++i) {
    bool ok = true;
    for (int j = 0; j < m; ++j) {
      if (!check(i, n, s[j], c[j])) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
