#include <bits/stdc++.h>
using namespace std;
int indegree[100010];
pair<int, int> query[100010];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &query[i].first, &query[i].second);
  }
  int left = 1;
  int right = m;
  int dap = m + 1;
  while (left <= right) {
    memset(indegree, 0, sizeof(indegree));
    vector<vector<int>> vt;
    vt.resize(n + 1);
    int mid = (left + right) / 2;
    for (int i = 1; i <= mid; i++) {
      vt[query[i].first].push_back(query[i].second);
      indegree[query[i].second]++;
    }
    queue<int> qu;
    int update = 0;
    int cnt = 0;
    int ch = 0;
    for (int i = 1; i <= n; i++) {
      if (!indegree[i]) {
        qu.push(i);
        cnt++;
      }
    }
    if (cnt >= 2) update = 1;
    while (qu.size()) {
      ch++;
      int curr = qu.front();
      qu.pop();
      int hh = 0;
      for (int i = 0; i < vt[curr].size(); i++) {
        int next = vt[curr][i];
        indegree[next]--;
        if (!indegree[next]) {
          qu.push(next);
          hh++;
        }
      }
      if (hh >= 2) update = 1;
    }
    if (ch != n) update = 1;
    if (update)
      left = mid + 1;
    else {
      right = mid - 1;
      dap = min(dap, mid);
    }
  }
  if (dap == m + 1)
    puts("-1");
  else
    printf("%d", dap);
}
