#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100001;
int n, m, x, y, indeg[MAXN];
vector<int> adj[MAXN];
vector<pair<int, int> > edge;
bool possible(int sz) {
  for (int i = 0; i <= n; ++i) {
    adj[i].clear();
    indeg[i] = 0;
  }
  for (int i = 0; i < sz; ++i) {
    adj[edge[i].first].push_back(edge[i].second);
    indeg[edge[i].second]++;
  }
  set<int> st;
  for (int i = 1; i <= n; ++i) {
    if (indeg[i] == 0) st.insert(i);
  }
  while (st.size() == 1) {
    int curr = *st.begin();
    st.erase(curr);
    for (auto it : adj[curr]) {
      indeg[it]--;
      if (indeg[it] == 0) st.insert(it);
    }
  }
  if (st.size() == 0) return true;
  return false;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &x, &y);
    edge.push_back({x, y});
  }
  int l = 1, r = m, mid;
  while (l <= r) {
    mid = (l + r) / 2;
    if (possible(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  if (l <= m)
    printf("%d", l);
  else
    printf("-1");
}
