#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> num(N, 0);
  vector<bool> designated(N, false);
  bool flag = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (designated.at(s - 1) && num.at(s - 1) != c) {
      flag = false;
    } else {
      num.at(s - 1) = c;
      designated.at(s - 1) = true;
    }
  }
  if (num.at(0) == 0 && N != 1) flag = false;
  if (flag) {
    for (int i = 0; i < N; i++) {
      cout << num.at(i);
    }
    cout << endl;
  } else {
    cout << "-1" << endl;
  }
}
