#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> c(N);
  bool ok = true;
  for (int i = 0; i < M; i++) {
    int s, tc;
    cin >> s >> tc;
    if (tc == 0) {
      continue;
    }
    if (c[s - 1] == 0) {
      c[s - 1] = tc;
    }
    if (c[s - 1] != tc) {
      ok = false;
    }
  }
  if (!ok || c.at(0) == 0 && N > 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    cout << c.at(i);
  }
  cout << endl;
  return 0;
}
