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