#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ans(N, 0);
  bool TF = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (ans.at(s - 1) == 0 || ans.at(s - 1) == c) {
      ans.at(s - 1) = c;
    } else {
      TF = false;
      break;
    }
  }
  if (ans.at(0) == 0) {
    TF = false;
  }
  int answer = 0;
  if (TF == true) {
    int ten = 1;
    for (int i = 0; i < N - 1; i++) {
      ten *= 10;
    }
    for (int i = 0; i < N; i++) {
      answer += ans.at(i) * ten;
      ten /= 10;
    }
    cout << answer << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
