#include <bits/stdc++.h>
using namespace std;
void zanj0() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const long long int N = 1e5 + 5;
vector<pair<long long int, long long int> > graph[N];
long long int n, m;
long long int inDegree[N];
bool ok(long long int k) {
  set<long long int> visited;
  for (long long int i = 1; i <= n; i++) inDegree[i] = 0;
  for (long long int i = 1; i <= n; i++) {
    for (auto& it : graph[i]) {
      if (it.second <= k) {
        inDegree[it.first]++;
      }
    }
  }
  queue<long long int> q;
  for (long long int i = 1; i <= n; i++) {
    if (inDegree[i] == 0) q.push(i);
  }
  while (!q.empty()) {
    long long int node = q.front();
    if (q.size() > 1) return false;
    visited.insert(node);
    q.pop();
    for (auto& it : graph[node]) {
      if (it.second <= k) {
        inDegree[it.first]--;
        if (inDegree[it.first] == 0) {
          q.push(it.first);
        }
      }
    }
  }
  return (long long int)visited.size() == n;
}
void solve() {
  cin >> n >> m;
  long long int u, v;
  for (long long int i = 1; i <= m; i++) {
    cin >> u >> v;
    graph[u].push_back({v, i});
  }
  long long int low = 1;
  long long int high = m;
  long long int ret = -1;
  while (low <= high) {
    long long int mid = low + (high - low) / 2;
    if (ok(mid)) {
      ret = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  cout << ret << "\n";
}
int32_t main() {
  zanj0();
  solve();
  cerr << "Time : " << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
