#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> t(M, -1);
  for (int i = 0; i < M; i++) {
    int k, x;
    cin >> k >> x;
    --k;
    if (t[k] == -1 || t[k] == x) {
      t[k] = x;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (N == 1) {
    for (auto &x : t) cout << max(x, 0);
    cout << endl;
  } else {
    if (t[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (t[0] == -1) t[0] = 1;
    for (auto &x : t) cout << max(x, 0);
    cout << endl;
  }
}
