#include <bits/stdc++.h>
using namespace std;
int N, M;
int A[100005][2];
vector<int> Graph[100005];
bool vis[100005];
vector<int> L;
int P[100005];
void dfs(int source) {
  if (vis[source]) return;
  for (auto it = Graph[source].begin(); it != Graph[source].end(); ++it)
    dfs(*it);
  vis[source] = true;
  L.push_back(source);
}
int main() {
  cin >> N >> M;
  int a, b;
  for (int i = 0; i < M; ++i) {
    scanf("%d %d", &a, &b);
    A[i][0] = a;
    A[i][1] = b;
    Graph[a].push_back(b);
  }
  for (int i = 1; i < N + 1; ++i)
    if (!vis[i]) dfs(i);
  reverse(L.begin(), L.end());
  for (int i = 0; i < L.size() - 1; ++i) P[L[i]] = L[i + 1];
  int cont = 0;
  for (int i = 0; i < M; ++i) {
    if (P[A[i][0]] == A[i][1]) cont++;
    if (cont == (N - 1)) {
      cout << (i + 1) << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
