#include <bits/stdc++.h>
using namespace std;
vector<bool> discovered;
vector<vector<int>> adjList;
vector<int> topSort;
int n, m;
void top(int i) {
  discovered[i] = true;
  for (int u : adjList[i]) {
    if (!discovered[u]) top(u);
  }
  topSort.push_back(i);
}
void always() {
  discovered.clear();
  discovered.assign(n + 1, 0);
  adjList.clear();
  adjList.resize(n + 1);
  topSort.clear();
}
int main() {
  int a, b, l, r, mid, ans;
  cin >> n >> m;
  vector<pair<int, int>> ge;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    ge.push_back(make_pair(a, b));
  }
  l = 0, r = m - 1, ans = -1;
  while (r - l >= 0) {
    always();
    map<pair<int, int>, bool> present;
    mid = l + (r - l) / 2;
    bool can = true;
    for (int i = 0; i <= mid; i++)
      adjList[ge[i].first].push_back(ge[i].second), present[ge[i]] = 1;
    for (int i = 1; i <= n; i++) {
      if (!discovered[i]) top(i);
    }
    reverse(topSort.begin(), topSort.end());
    for (int i = 0; i < n - 1; i++) {
      if (!present.count(make_pair(topSort[i], topSort[i + 1]))) can = false;
    }
    if (can) {
      ans = mid + 1;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans;
}
