#include <bits/stdc++.h>
using namespace std;
int n, m, v, u;
pair<int, int> edg[100007];
int ok(int x) {
  set<int> se;
  int indeg[n + 1];
  std::vector<int> adj[n + 1], radj[n + 1];
  memset(indeg, 0, sizeof(indeg));
  for (int i = 0; i < x; i++) {
    ++indeg[edg[i].second];
    adj[edg[i].first].push_back(edg[i].second);
    radj[edg[i].second].push_back(edg[i].first);
    se.insert(edg[i].first);
    se.insert(edg[i].second);
  }
  if (se.size() != n) return 0;
  int cur = -1, rr = 0, len = 0;
  for (int i = 1; i <= n; i++) {
    if (!indeg[i]) cur = i, ++rr;
  }
  if (cur == -1 or rr > 1) return 0;
  while (1) {
    int rr = 0;
    ++len;
    for (int e : adj[cur]) {
      --indeg[e];
      if (!indeg[e]) cur = e, ++rr;
    }
    if (rr != 1) break;
  }
  return (len == n);
}
int main() {
  std::cin >> n >> m;
  for (int i = 0; i < m; i++) {
    std::cin >> edg[i].first >> edg[i].second;
  }
  int l = 1, r = m, mid;
  while (l <= r) {
    mid = l + (r - l) / 2;
    bool kk = ok(mid);
    if (!kk)
      l = mid + 1;
    else
      r = mid - 1;
  }
  if (l > m) return 0 * printf("-1\n");
  printf("%d\n", l);
}
