#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[9];
  for (int i = 0; i < (n + 1); ++i) a[i] = -1;
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    if (a[n - s] != -1 && a[n - s] != c) {
      cout << -1 << endl;
      return (0);
    }
    a[n - s] = c;
  }
  int k[] = {0, 10, 100, 1000};
  for (int i = k[n - 1]; i < k[n]; i++) {
    int t = i;
    vector<int> d;
    while (t) {
      d.push_back(t % 10);
      t /= 10;
    }
    bool f = false;
    for (int j = 0; j < (d.size()); ++j) {
      if (a[j] != -1 && a[j] != d[j]) f = true;
    }
    if (!f) {
      cout << i << endl;
      return (0);
    }
  }
  cout << -1 << endl;
  return (0);
}
