#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1e5 + 5;
int dp[N];
int res[N];
vector<pair<int, int>> E[N];
int check(int u) {
  if (dp[u]) return dp[u];
  dp[u] = 1;
  for (const auto& p : E[u]) {
    int to = p.first;
    if (check(to) + 1 > dp[u]) {
      dp[u] = dp[to] + 1;
      res[u] = max(res[to], p.second);
    }
  }
  return dp[u];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    E[x].emplace_back(y, i + 1);
  }
  for (int i = 0; i < n; i++) {
    if (check(i) == n) {
      cout << res[i] << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
