#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  bool isExist = true;
  map<int, int> mp;
  for (int i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    if (mp.count(s) == 0) {
      if (s == 1 && c == 0) isExist = false;
      mp.insert(make_pair(s, c));
    } else {
      if (mp[s] != c) isExist = false;
    }
  }
  if (!isExist) {
    cout << -1 << endl;
    return 0;
  }
}
