#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
vector<pair<int, int> > G[maxn];
int dp[maxn];
int res[maxn];
int DFS(int u) {
  if (dp[u]) return dp[u];
  dp[u] = 1;
  for (int j = 0; j < G[u].size(); j++) {
    pair<int, int> p = G[u][j];
    int v = p.first;
    if (DFS(v) + 1 > dp[u]) {
      dp[u] = dp[v] + 1;
      res[u] = max(res[v], p.second);
    }
  }
  return dp[u];
}
int main() {
  int n, m, u, v, i;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> u >> v;
    u--, v--;
    G[u].push_back(pair<int, int>(v, i + 1));
  }
  for (i = 0; i < n; i++) {
    if (DFS(i) == n) {
      cout << res[i] << "\n";
      return 0;
    }
  }
  cout << "-1\n";
  return 0;
}
