#include <bits/stdc++.h>
using namespace std;
int n, m, head[100010], cnt, du[100010], u[100010], v[100010], dis[100010];
queue<int> q;
struct edge {
  int to, next;
} e[200010];
inline void insert(int u, int v) {
  e[++cnt].to = v, e[cnt].next = head[u], head[u] = cnt;
  du[v]++;
}
inline bool check(int x) {
  cnt = 0;
  memset(head, 0, sizeof(head));
  memset(dis, 0, sizeof(dis));
  memset(du, 0, sizeof(du));
  for (int i = 1; i <= x; i++) insert(v[i], u[i]);
  int pos = 0;
  for (int i = 1; i <= n; i++) {
    if (du[i]) continue;
    if (pos) return false;
    pos = i;
  }
  q.push(pos);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i; i = e[i].next) {
      int v = e[i].to;
      dis[v] = max(dis[v], dis[u] + 1);
      du[v]--;
      if (!du[v]) q.push(v);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dis[i] == n - 1) return true;
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &u[i], &v[i]);
  int l = 1, r = m, ans = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", ans);
  return 0;
}
