#include <bits/stdc++.h>
using namespace std;
vector<int> arr[100010];
int n, m;
bool flag;
stack<int> st;
int vis[100010];
pair<int, int> in[100010];
int dp[100010];
void dfs(int s) {
  vis[s] = -1;
  for (int i = 0; i < arr[s].size(); ++i) {
    int to = arr[s][i];
    if (vis[to] == -1)
      flag = true;
    else if (!vis[to])
      dfs(to);
  }
  vis[s] = 1;
  st.push(s);
}
int solve(int s) {
  int &ret = dp[s];
  if (ret != -1) return ret;
  ret = 1;
  for (int i = 0; i < arr[s].size(); ++i) {
    ret = max(ret, 1 + solve(arr[s][i]));
  }
  return ret;
}
bool ok(int mid) {
  for (int i = 1; i <= n; ++i) arr[i].clear();
  memset(vis, 0, sizeof(vis));
  flag = false;
  memset(dp, -1, sizeof(dp));
  while (!st.empty()) st.pop();
  for (int i = 1; i <= mid; ++i) {
    arr[in[i].first].push_back(in[i].second);
  }
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) dfs(i);
  if (solve(st.top()) < n) return false;
  return true;
}
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  int u, v;
  for (int i = 1; i <= m; ++i) {
    scanf("%d", &in[i].first);
    scanf("%d", &in[i].second);
  }
  int l = 1, r = m, mid;
  while (l < r) {
    mid = l + (r - l) / 2;
    if (ok(mid))
      r = mid;
    else
      l = mid + 1;
  }
  if (l == m && !ok(l))
    printf("-1\n");
  else
    printf("%d\n", l);
}
