#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > edges;
vector<int> graph[100005];
vector<int> res;
int dp[100005];
int dfs(int idx) {
  if (dp[idx] != -1) return dp[idx];
  int ans = 1;
  for (int x : graph[idx]) ans = max(ans, 1 + dfs(x));
  return (dp[idx] = ans);
}
bool func(int n, int m) {
  int i;
  for (i = 1; i <= n; i++) graph[i].clear();
  memset(dp, -1, sizeof dp);
  for (i = 0; i < m; i++) graph[edges[i].first].push_back(edges[i].second);
  int val = 0;
  for (i = 1; i <= n; i++) val = max(val, dfs(i));
  return (val == n);
}
void solve() {
  int n, m, i, j;
  scanf("%d", &n);
  scanf("%d", &m);
  edges.resize(m);
  for (i = 0; i < m; i++)
    scanf("%d", &edges[i].first), scanf("%d", &edges[i].second);
  int low = 1, up = m;
  int mid;
  while (low <= up) {
    mid = (low + up) >> 1;
    if (func(n, mid))
      up = mid - 1;
    else
      low = mid + 1;
  }
  if (low == m + 1) low = -1;
  cout << low << "\n";
}
int main() {
  int t = 1;
  while (t--) solve();
  return 0;
}
