#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(N, -1);
  int flag_err = 0;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (vec.at(N - s) == -1) {
      vec.at(N - s) = c;
    } else if (vec.at(N - s) != c) {
      flag_err = 1;
      break;
    }
  }
  for (int i = 0; i < N - 1; i++)
    if (vec.at(i) == -1) vec.at(i) = 0;
  if (N >= 2) {
    if (vec.at(N - 1) == -1) vec.at(N - 1) = 1;
    if (vec.at(N - 1) == 0) flag_err = 1;
  }
  int ans = -1, pw = 1;
  if (flag_err == 0) {
    ans = 0;
    for (int i = 0; i < N; i++) {
      ans += vec.at(i) * pw;
      pw *= 10;
    }
  }
  cout << ans << endl;
}
