#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, m, y = 1;
  cin >> n >> m;
  vector<long> s(m);
  vector<long> c(m);
  for (long i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  for (long i = 0; i < m;) {
    if (s[i] == s[i + y] && c[i] == c[i + 1]) {
      cout << -1 << endl;
      break;
    } else {
      if (y < m) {
        y++;
      } else {
        i++;
        m = m - 1;
      }
    }
  }
}
