#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > g;
vector<int> g_rev;
vector<int> dist, prv, num, color;
set<pair<int, int> > st;
void dfs(int vertex) {
  color[vertex] = 1;
  for (auto& pr : g[vertex]) {
    if (color[pr.first] == 0) dfs(pr.first);
    if (dist[vertex] < dist[pr.first] + 1) {
      dist[vertex] = dist[pr.first] + 1;
      num[vertex] = pr.second;
      prv[vertex] = pr.first;
    } else if (dist[vertex] == dist[pr.first] + 1) {
      num[vertex] = min(num[vertex], pr.second);
    }
  }
  color[vertex] = 2;
}
int get_ans(int pos) {
  dfs(pos);
  int cnt = 1, ans = -1;
  while (prv[pos] != -1) {
    ans = max(ans, num[pos]);
    cnt++;
    pos = prv[pos];
  }
  if (cnt != dist.size()) return -1;
  return ans;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  g.resize(n);
  dist.resize(n, 0);
  prv.resize(n, -1);
  num.resize(n, -1);
  g_rev.resize(n, 0);
  color.resize(n, 0);
  int u, v;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    u--;
    v--;
    g_rev[v]++;
    g[u].push_back(make_pair(v, i + 1));
  }
  int tres = 0, pos = -1;
  for (int i = 0; i < n; i++) {
    if (g_rev[i] == 0) {
      tres++;
      pos = i;
    }
  }
  if (tres != 1) {
    printf("-1\n");
    return 0;
  }
  int res = get_ans(pos);
  printf("%d\n", res);
  return 0;
}
