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