#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[3];
  int n, m, s, c;
  cin >> n >> m;
  int ans;
  a[0] = 0;
  a[1] = 0;
  a[2] = 0;
  for (int i = 0; i < int(m); i++) {
    cin >> s >> c;
    if (a[n - s] != 0 && a[n - s] != c) {
      ans = -1;
      break;
    } else {
      a[n - s] = c;
    }
  }
  if (ans != -1) {
    if (n == 3 && a[2] == 0 || n == 2 && a[1] == 0) {
      ans = -1;
    } else {
      ans = a[2] * 100 + a[1] * 10 + a[0];
    }
  }
  cout << ans << endl;
  return 0;
}
