#include <bits/stdc++.h>
namespace patch {
template <typename T>
std::string to_string(const T& n) {
  std::ostringstream stm;
  stm << n;
  return stm.str();
}
}  // namespace patch
using namespace std;
long long ans[100005];
long long N, M;
vector<vector<long long> > adj;
bool vis[100005];
int in[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M;
  map<pair<int, int>, int> ind;
  adj.resize(1e5 + 5);
  for (int i = 0; i < M; i++) {
    long long X, Y;
    cin >> X >> Y;
    in[Y]++;
    ind[{X, Y}] = i;
    adj[X].push_back(Y);
  }
  int mx = 0;
  priority_queue<int> pq;
  for (int i = 1; i <= N; i++) {
    if (!in[i]) {
      pq.push(i);
    }
  }
  while (!pq.empty()) {
    int curr = pq.top();
    pq.pop();
    if (pq.size()) {
      cout << -1;
      return 0;
    }
    for (int i = 0; i < adj[curr].size(); i++) {
      int child = adj[curr][i];
      in[child]--;
      if (in[child] == 0) {
        pq.push(child);
        mx = max(mx, ind[{curr, child}]);
      }
    }
  }
  cout << mx + 1;
  return 0;
}
