#include <bits/stdc++.h>
using namespace std;
long long int f[100005] = {0}, l[100005] = {0};
vector<pair<long long int, long long int> > v[100005];
pair<long long int, long long int> ans[100005];
pair<long long int, long long int> dfs(long long int x) {
  long long int idx = 0, sum = 0, y, j;
  pair<long long int, long long int> g;
  for (long long int i = 0; i < v[x].size(); i++) {
    y = v[x][i].first;
    j = v[x][i].second;
    if (ans[y].first == -1 && ans[y].second == -1)
      g = dfs(y);
    else
      g.first = ans[y].first, g.second = ans[y].second;
    if (g.first > sum) sum = g.first, idx = max(j, g.second);
  }
  ans[x].first = sum + 1, ans[x].second = idx;
  return {sum + 1, idx};
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, m, x, y;
  cin >> n >> m;
  pair<long long int, long long int> g;
  memset(ans, -1, sizeof(ans));
  for (long long int i = 1; i <= m; i++) {
    cin >> x >> y;
    v[x].push_back(make_pair(y, i));
    f[x] = 1;
    l[y] = 1;
  }
  for (long long int i = 1; i <= n; i++) {
    if (f[i] == 1 && l[i] == 0) {
      g = dfs(i);
      break;
    }
  }
  if (g.first == n)
    cout << g.second << endl;
  else
    cout << "-1\n";
}
