#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
vector<int> adj[maxn];
vector<int> v;
bool visit[maxn], recstack[maxn], cycle;
map<pair<int, int>, int> m;
int n, m1, u, v1, ans;
long long modx(long long base, long long ex) {
  long long ans = 1LL, val = base;
  while (ex > 0LL) {
    if (ex & 1LL) ans = (ans * val) % 1000000007LL;
    val = (val * val) % 1000000007LL;
    ex = ex >> 1LL;
  }
  return ans;
}
void dfs(int start) {
  visit[start] = true;
  recstack[start] = true;
  for (int i = 0; i < adj[start].size(); i++) {
    int node = adj[start][i];
    if (!visit[node]) dfs(node);
    if (recstack[node]) cycle = true;
  }
  recstack[start] = false;
  v.push_back(start);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m1;
  for (int i = 1; i <= m1; i++) {
    cin >> u >> v1;
    adj[u].push_back(v1);
    m[make_pair(u, v1)] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (!visit[i]) {
      dfs(i);
    }
  }
  for (int i = 1; i < v.size(); i++) {
    if (m.find(make_pair(v[i], v[i - 1])) == m.end())
      cycle = true;
    else
      ans = max(ans, m[make_pair(v[i], v[i - 1])]);
  }
  if (!cycle)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
