#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b, f;
  cin >> n >> m;
  int c[m][2];
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (c[a][1] == 0) {
      c[a][0] = b;
      c[a][1] = 1;
    } else if (c[m][0] != b) {
      cout << -1 << endl;
      i = m;
    }
    f = 10 ^ (n - a) * b;
  }
  if (f != -1) cout << f << endl;
}
