#include <bits/stdc++.h>
using namespace std;
void DFS(int s, vector<vector<pair<int, int>>>& adj, vector<int>& order,
         vector<bool>& visited) {
  visited[s] = 1;
  for (int i = 0; i < adj[s].size(); ++i) {
    if (!visited[adj[s][i].first]) DFS(adj[s][i].first, adj, order, visited);
  }
  order.push_back(s);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int>>> adj(n, vector<pair<int, int>>());
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    adj[x - 1].push_back(make_pair(y - 1, i + 1));
  }
  vector<bool> visited(n, 0);
  vector<int> order;
  for (int i = 0; i < n; ++i) {
    if (!visited[i]) DFS(i, adj, order, visited);
  }
  reverse(order.begin(), order.end());
  vector<int> dist(n, 0);
  dist[order[0]] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < adj[order[i]].size(); ++j) {
      dist[adj[order[i]][j].first] = 1 + dist[order[i]];
    }
  }
  if (dist[order[n - 1]] == n) {
    int ans = 0;
    for (int i = 0; i < order.size() - 1; ++i) {
      for (int j = 0; j < adj[order[i]].size(); ++j) {
        if (adj[order[i]][j].first == order[i + 1]) {
          ans = max(ans, adj[order[i]][j].second);
        }
      }
    }
    cout << ans << endl;
  } else
    cout << -1 << endl;
  return 0;
}
