#include <bits/stdc++.h>
using namespace std;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const long long NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;
const int N = 1e5 + 10;
int n, m, mark[N], dp[N];
vector<int> adj[N];
pair<int, int> edg[N];
void dfs(int v) {
  mark[v] = 1;
  for (auto &u : adj[v]) {
    if (!mark[u]) dfs(u);
    dp[v] = max(dp[v], dp[u] + 1);
  }
}
bool check(int t) {
  for (int i = 1; i <= t; i++) adj[edg[i].first].emplace_back(edg[i].second);
  for (int i = 1; i <= n; i++)
    if (!mark[i]) dfs(i);
  int mxp = 0;
  for (int i = 1; i <= n; i++) {
    ;
    mxp = max(mxp, dp[i]);
  }
  for (int i = 1; i <= n; i++) mark[i] = 0, dp[i] = 0, adj[i].clear();
  return mxp == n - 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, u, v; i <= m; i++) scanf("%d%d", &u, &v), edg[i] = {u, v};
  int lo = 1, ans = m + 1, hi = m, mid;
  while (lo <= hi) {
    mid = (lo + hi) >> 1;
    if (check(mid))
      ans = mid, hi = mid - 1;
    else
      lo = mid + 1;
  }
  if (ans > m)
    printf("-1\n");
  else
    printf("%d\n", ans);
}
