#include <bits/stdc++.h>
using namespace std;
typedef struct _P {
  int of, in;
} P;
bool possible(vector<P> &vec, int m, int n) {
  vector<int> cnt(n + 1, 0);
  for (int i = 0; i < m; ++i) {
    cnt[vec[i].in] += 1;
  }
  int h = 0;
  for (int i = 1; i <= n; ++i) {
    if (cnt[i] == 0) {
      if (h == 0) {
        h = i;
      } else {
        return false;
      }
    }
  }
  if (h == 0) return false;
  vector<vector<int>> link(n + 1);
  for (int i = 0; i < m; ++i) {
    link[vec[i].of].push_back(vec[i].in);
  }
  int used = 1;
  while (used < n) {
    for (int i = 0; i < link[h].size(); ++i) {
      cnt[link[h][i]] -= 1;
    }
    int nh = 0;
    for (int i = 0; i < link[h].size(); ++i) {
      if (cnt[link[h][i]] == 0) {
        if (nh == 0) {
          nh = link[h][i];
        } else {
          return false;
        }
      }
    }
    if (nh == 0) return false;
    used += 1;
    h = nh;
  }
  return true;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> vec(m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &vec[i].of, &vec[i].in);
  }
  if (not possible(vec, m, n)) {
    cout << (-1);
    exit(0);
  }
  int lft = 0, rht = m;
  while (lft + 1 < rht) {
    int mid = (rht + lft) / 2;
    if (possible(vec, mid, n)) {
      rht = mid;
    } else {
      lft = mid;
    }
  }
  cout << rht;
  return 0;
}
