#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> cond(3, 0);
  vector<bool> tof(3, false);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (tof[s - 1] == true && c != cond[s - 1]) {
      cout << -1 << endl;
      return 0;
    }
    cond[s - 1] = c;
    tof[s - 1] = true;
  }
  int k = 0;
  if (n != 1) {
    k = 1;
    for (int i = 0; i < n - 1; i++) {
      k *= 10;
    }
  }
  for (int i = k; i < 1000; i++) {
    int a = i / 100, b = (i - a * 100) / 10, c = i % 10;
    if (cond[0] == a && cond[1] == b && cond[2] == c) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
