#include <bits/stdc++.h>
using namespace std;
const int N = 10 + 1e6;
vector<int> Adj[N];
vector<pair<int, int> > edge;
int dp[N];
int n, m, a, b;
int dfs(int idx) {
  if (int(Adj[idx].size()) == 0) return dp[idx] = 0;
  if (dp[idx] != -1) return dp[idx];
  dp[idx] = 0;
  for (int i = 0; i < int(int(Adj[idx].size())); i++) {
    int u = Adj[idx][i];
    dp[idx] = max(dp[idx], dfs(u) + 1);
  }
  return dp[idx];
}
bool valid(int idx) {
  for (int i = 0; i < int(n); i++) Adj[i].clear();
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < int(idx); i++) {
    Adj[edge[i].first].push_back(edge[i].second);
  }
  bool flag = 0;
  for (int i = 0; i < int(n); i++) flag |= dfs(i) == (n - 1);
  return flag;
}
int bs(int second, int e) {
  while (second < e) {
    int mid = (second + (e - second) / 2);
    if (valid(mid))
      e = mid;
    else
      second = mid + 1;
  }
  return second;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < int(m); i++) {
    scanf("%d %d", &a, &b);
    a--, b--;
    edge.push_back(make_pair(a, b));
  }
  if (!valid(m)) {
    printf("-1\n");
    return 0;
  }
  int ans = bs(1, m);
  printf("%d\n", ans);
  return 0;
}
