#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, c;
  cin >> n >> m;
  vector<int> a(n, -1);
  bool ans = true;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> c;
    s--;
    if (a[s] == -1)
      a[s] = c;
    else if (a[s] != c)
      ans = false;
  }
  cout << "-1"
       << "\n";
}
