#include <bits/stdc++.h>
using namespace std;
stack<int> st;
bool vis[100007];
std::vector<pair<int, int> > adj[100007], par[100007];
int res[100007], ans[100007];
void toposort(int v) {
  vis[v] = 1;
  for (int i = 0; i < adj[v].size(); i++) {
    if (!vis[adj[v][i].first]) toposort(adj[v][i].first);
  }
  st.push(v);
}
int main() {
  int n, m, i, x, y;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    adj[y].push_back(make_pair(x, i + 1));
    par[x].push_back(make_pair(y, i + 1));
  }
  for (i = 1; i <= n; i++)
    if (!vis[i]) toposort(i);
  int v;
  while (!st.empty()) {
    v = st.top();
    st.pop();
    int cur = 0;
    for (i = 0; i < par[v].size(); i++) {
      if (res[par[v][i].first] > cur) {
        cur = res[par[v][i].first];
        ans[v] = max(par[v][i].second, ans[par[v][i].first]);
      }
    }
    res[v] = cur + 1;
    if (res[v] == n) {
      cout << ans[v] << endl;
      return 0;
    }
  }
  cout << "-1\n";
}
