#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int num[3];
  int ans = 0;
  bool kasana = false;
  for (int i = 0; i < 3; i++) num[i] = 0;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (num[s] != 0 && num[s] != c) kasana = true;
    num[s] = c;
  }
  if (kasana) cout << -1 << endl;
  return 0;
  if (num[N] == 0) cout << -1 << endl;
  return 0;
  ans += num[0] * 100 + num[1] * 10 + num[2] * 1;
  cout << ans << endl;
  return 0;
}
