#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int n, m, d[maxn], u[maxn], v[maxn];
vector<int> G[maxn];
int dp[maxn];
int dfs(int u) {
  if (dp[u] != -1) return dp[u];
  int ret = 1;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    ret = max(dfs(v) + 1, ret);
  }
  return dp[u] = ret;
}
bool check(int mid) {
  memset(d, 0, sizeof(d));
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) G[i].clear();
  for (int i = 1; i <= mid; i++) G[u[i]].push_back(v[i]), d[v[i]]++;
  int st = 0, cnt = 0;
  for (int i = 1; i <= n; i++)
    if (!d[i]) st = i, cnt++;
  if (cnt != 1) return 0;
  int ret = dfs(st);
  return ret == n;
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    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))
        r = mid - 1, ans = mid;
      else
        l = mid + 1;
    }
    printf("%d\n", ans);
  }
}
