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