#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  char s[3];
  struct Data {
    int number;
    int order;
  };
  Data A[5];
  scanf("%d %d\n", N, M);
  for (int i = 0; i < M; i++) {
    scanf("%d %d\n", A[i].order, A[i].number);
  }
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (A[i].order == A[j].order && i != j) {
        cout << -1;
        return 0;
      }
    }
  }
  return 0;
}
