#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> arr;
long long n, m;
vector<bool> temporary;
vector<bool> permanent;
vector<vector<int>> graph;
vector<int> dp;
int topSort(int v) {
  if (permanent[v]) return dp[v];
  if (temporary[v]) return -1;
  temporary[v] = 1;
  int res = 0;
  for (auto elem : graph[v]) {
    res = max(res, topSort(elem));
    if (res == -1) {
      return -1;
    }
  }
  permanent[v] = 1;
  return dp[v] = 1 + res;
}
bool check(int a) {
  vector<bool> visited(n + 1, 0);
  dp.clear();
  graph.clear();
  permanent.clear();
  temporary.clear();
  temporary.resize(n + 1, 0);
  permanent.resize(n + 1, 0);
  dp.resize(n + 1);
  graph.resize(n + 1);
  for (int i = 0; i < a; i++) {
    graph[arr[i].first].push_back(arr[i].second);
    visited[arr[i].second] = 1;
  }
  int counter = 0;
  bool res = true;
  int last = 0;
  for (int i = 0; i < n + 1; i++) {
    if (visited[i] == 0) {
      counter++;
      last = i;
    }
  }
  if (counter > 2) res = false;
  if (topSort(last) != n) res = false;
  return res;
}
int main() {
  cin >> n >> m;
  arr.resize(m);
  for (int i = 0; i < m; i++) {
    long long a, b;
    cin >> a;
    cin >> b;
    arr[i] = {a, b};
  }
  int low = 1;
  int high = m;
  int mid = 0;
  int result = high + 5;
  while (high >= low) {
    mid = low + (high - low) / 2;
    if (check(mid)) {
      result = min(result, mid);
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  if (result == high + 5) result = -1;
  cout << result << endl;
}
