#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:36777216")
const int Direction[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
const int Nmax = 200100;
int n, m;
vector<vector<int> > g;
map<pair<int, int>, int> st;
vector<int> topSort;
bool used[Nmax];
void dfs(int v) {
  used[v] = true;
  for (int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    if (!used[u]) dfs(u);
  }
  topSort.push_back(v);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  g.resize(n + 1);
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    st[make_pair(x, y)] = i;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (!used[i]) dfs(i);
  reverse(topSort.begin(), topSort.end());
  assert(topSort.size() == n);
  for (int i = 0; i + 1 < n; i++) {
    if (st.find(make_pair(topSort[i], topSort[i + 1])) == st.end()) {
      cout << -1 << endl;
      return 0;
    }
    ans = max(ans, st[make_pair(topSort[i], topSort[i + 1])]);
  }
  cout << ans << endl;
  return 0;
}
