#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long n, m, ans = N;
vector<long long> g[N];
long long vis[N], deg[N], dp[N], calc[N];
map<pair<long long, long long>, long long> mp;
void dfs(long long v) {
  long long count = 0;
  dp[v] = 1;
  calc[v] = N;
  for (auto j : g[v]) {
    count++;
    if (!vis[j]) dfs(j);
    if (dp[j] + 1 > dp[v]) {
      dp[v] = dp[j] + 1;
      calc[v] = max(calc[j], mp[{v, j}]);
    } else if (dp[j] + 1 == dp[v]) {
      dp[v] = dp[j] + 1;
      calc[v] = min(calc[v], max(calc[j], mp[{v, j}]));
    }
  }
  vis[v] = 1;
  if (!count) calc[v] = 0;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(vis, 0, sizeof(vis));
  memset(deg, 0, sizeof(deg));
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    long long u, v;
    cin >> u >> v;
    deg[v]++;
    g[u].push_back(v);
    mp[{u, v}] = i;
  }
  bool flag = true;
  queue<long long> q;
  long long root;
  vector<long long> arr;
  for (long long i = 1; i <= n; i++) {
    if (!deg[i]) {
      q.push(i);
      root = i;
      arr.push_back(i);
    }
  }
  while (!q.empty()) {
    flag = flag & (q.size() == 1);
    long long v = q.front();
    q.pop();
    for (auto j : g[v]) {
      deg[j]--;
      if (!deg[j]) {
        q.push(j);
        arr.push_back(j);
      }
    }
  }
  flag = flag & (arr.size() == n);
  if (flag) {
    dfs(root);
    cout << calc[root];
  } else
    cout << -1;
  return 0;
}
