#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M;
  cin >> N >> M;
  long long min = -1;
  vector<long long> a(M);
  vector<long long> b(M);
  for (long long i = 0; i < (M); i++) {
    cin >> a.at(i);
    cin >> b.at(i);
  }
  vector<long long> num(N, -1);
  bool check = true;
  long long ans = 0;
  if (M != 0) {
    for (long long i = 0; i < (M); i++) {
      if ((num.at(a.at(i) - 1) == -1 || num.at(a.at(i) - 1) == b.at(i)) &&
          N >= a.at(i)) {
        num.at(a.at(i) - 1) = b.at(i);
      } else {
        check = false;
        break;
      }
    }
    for (long long i = 0; i < (3); i++) {
      if (num.at(i) == -1) {
        num.at(i) = 0;
      }
      ans += num.at(2 - i) * (pow(10, i));
    }
    if (ans / (pow(10, N - 1)) == 0 || ans / (pow(10, N - 1)) >= 10) {
      check = false;
    }
    if (check) {
      min = ans;
    }
    cout << min << endl;
  }
  return 0;
}
