#include <bits/stdc++.h>
const int SZ = 1e5 + 5;
using namespace std;
int n, m;
int dp[SZ], u[SZ], v[SZ];
vector<int> edge[SZ];
int DFS(int x) {
  if (dp[x] != -1) return dp[x];
  int res = 0;
  for (int i = 0; i < (int)edge[x].size(); i++)
    res = max(res, DFS(edge[x][i]) + 1);
  return dp[x] = res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", u + i, v + i);
    edge[u[i]].push_back(v[i]);
  }
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; i++) DFS(i);
  bool notExist = 1;
  for (int i = 1; i <= n; i++)
    if (dp[i] == n - 1) notExist = 0;
  if (notExist) {
    cout << -1;
    return 0;
  }
  int res = 0;
  for (int i = 0; i < m; i++)
    if (abs(dp[u[i]] - dp[v[i]]) == 1) res = max(res, i + 1);
  cout << res;
}
