#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m;
vector<pair<int, int>> edg;
int dl, tim, ml[N];
bool s[N];
vector<int> adj[N];
void read() {
  cin >> n >> m;
  edg.reserve(N);
  edg.push_back({0, 0});
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    edg.push_back({u, v});
  }
}
bool DFS(int v) {
  bool res = false;
  for (auto u : adj[v]) {
    if (!ml[u]) {
      dl++;
      DFS(u);
      dl--;
    }
    res = res || (dl + ml[u] + 1 == n - 1);
    ml[v] = max(ml[v], ml[u] + 1);
  }
  return res;
}
bool can(int k) {
  for (int i = 1; i <= n; i++) {
    adj[i].clear();
    s[i] = true;
    ml[i] = 0;
  }
  for (int i = 1; i <= k; i++) {
    adj[edg[i].first].push_back(edg[i].second);
    s[edg[i].second] = 0;
  }
  dl = 0;
  for (int i = 1; i <= n; i++)
    if (s[i]) {
      return DFS(i);
    }
  return 0;
}
int solve() {
  int l = 1, r = m, ans = -1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (can(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  read();
  cout << solve();
  return 0;
}
