#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int vis[n];
  memset(vis, -1, sizeof vis);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    --s;
    if (vis[s] != -1 && vis[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    vis[s] = c;
  }
  cout << -1 << endl;
  return 0;
}
