#include <bits/stdc++.h>
using namespace std;
struct edge {
  int from, to;
} p[101000];
struct node {
  int to, next;
} e[201000];
int n, m, cnt;
int in[101000];
int head[101000];
queue<int> q;
void add(int u, int v) {
  e[++cnt].to = v;
  e[cnt].next = head[u];
  head[u] = cnt;
}
bool can(int x) {
  cnt = 0;
  memset(head, 0, sizeof(head));
  memset(in, 0, sizeof(in));
  memset(head, 0, sizeof(head));
  while (!q.empty()) q.pop();
  for (int i = 1; i <= x; i++) {
    add(p[i].from, p[i].to);
    in[p[i].to]++;
  }
  int mn = 0, mx, top = 0;
  for (int i = 1; i <= n; i++) {
    if (in[i] == 0) mn++, mx = i;
  }
  if (mn > 1) return 0;
  q.push(mx);
  top = 1;
  while (!q.empty()) {
    if (q.size() != 1) return 0;
    int now = q.front();
    q.pop();
    for (int i = head[now]; i; i = e[i].next) {
      int to = e[i].to;
      in[to]--;
      if (!in[to]) q.push(to);
    }
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &p[i].from, &p[i].to);
  int l = 1, r = m, ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (can(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  if (ans)
    printf("%d\n", ans);
  else
    printf("-1\n");
  return 0;
}
