#include <bits/stdc++.h>
using namespace std;
long const N = 100010;
map<long, vector<pair<long, long> > > G;
bool start_node[N];
bool visited_node[N];
long dist[N];
long next_node[N];
void go(long node) {
  if (visited_node[node]) {
    return;
  }
  long result = 0;
  for (long i = 0; i < G[node].size(); i++) {
    go(G[node][i].first);
    if (result < dist[G[node][i].first]) {
      result = dist[G[node][i].first];
      next_node[node] = i;
    }
  }
  visited_node[node] = true;
  dist[node] = result + 1;
  return;
}
int main() {
  ios::sync_with_stdio(false);
  long n, m, in, in2;
  cin >> n >> m;
  for (long i = 0; i < m; i++) {
    cin >> in >> in2;
    G[in].push_back(make_pair(in2, i));
    start_node[in2] = true;
  }
  long startNode = -1;
  for (long i = 1; i <= n; i++) {
    if (!start_node[i]) {
      startNode = i;
      break;
    }
  }
  go(startNode);
  long ans = -1;
  if (dist[startNode] != n) {
    cout << -1;
    return 0;
  } else {
    for (int i = 0; i < n - 1; i++) {
      ans = max(ans, G[startNode][next_node[startNode]].second);
      startNode = G[startNode][next_node[startNode]].first;
    }
  }
  cout << ans + 1;
  return 0;
}
