#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> sc(N, -1);
  for (long long i = 0; i < (long long)(M); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (sc.at(s) != -1 && sc.at(s) != c) {
      cout << -1 << endl;
      return 0;
    }
    sc.at(s) = c;
  }
  if (sc.at(N - 1) == -1) {
    cout << -1 << endl;
    return 0;
  }
  int r;
  for (long long i = 0; i < (long long)(N); i++) {
    r += max(0, sc.at(i));
    r *= 10;
  }
  cout << r / 10 << endl;
}
