#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 5;
const long long LINF = (long long)1e18 + 5;
const double PI = acos(-1.0);
const int N = 100100;
int n, m;
int x[N], y[N];
int deg[N];
vector<int> g[N];
vector<int> cand;
bool can(int pref) {
  for (int i = 1; i <= n; i++) {
    g[i].resize(0);
    deg[i] = 0;
  }
  cand.clear();
  for (int i = 1; i <= pref; i++) {
    g[x[i]].push_back(y[i]);
    deg[y[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    if (deg[i] == 0) cand.push_back(i);
  }
  while (!cand.empty()) {
    if (cand.size() > 1) return false;
    vector<int> ncand;
    for (auto x : cand) {
      for (auto to : g[x]) {
        deg[to]--;
        if (deg[to] == 0) {
          ncand.push_back(to);
        }
      }
    }
    cand = ncand;
  }
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", x + i, y + i);
  }
  int l = 0, r = m + 1;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (can(mid))
      r = mid;
    else
      l = mid;
  }
  if (r == m + 1)
    puts("-1");
  else
    printf("%d\n", r);
}
