#include <bits/stdc++.h>
using namespace std;
const int N = 111111;
int n, m, best;
vector<set<pair<int, int>>> graph;
int visited[N], in[N];
int dfs(int parent, int node, int k) {
  if (visited[node] != -1) return visited[node];
  int ret = 0;
  for (auto p : graph[node]) {
    if (p.first == parent) continue;
    if (p.second > k) continue;
    ret = max(ret, 1 + dfs(node, p.first, k));
  }
  return visited[node] = ret;
}
bool check(int k) {
  for (int i = 0; i < n; ++i) visited[i] = -1;
  return dfs(-1, best, k) == n - 1;
}
void solve() {
  cin >> n >> m;
  graph.assign(n, set<pair<int, int>>());
  int u, v;
  for (int i = 1; i <= m; ++i) {
    cin >> u >> v;
    --u;
    --v;
    graph[u].insert({v, i});
    ++in[v];
  }
  for (int i = 0; i < n; ++i)
    if (in[i] == 0) {
      best = i;
      break;
    }
  int lo = 0, hi = m + 1;
  while (lo < hi) {
    int mid = lo + (hi - lo) / 2;
    if (check(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << (hi == m + 1 ? -1 : hi) << endl;
}
int main() {
  solve();
  return 0;
}
