#include <bits/stdc++.h>
using namespace std;
int in[100009], n, m, x, y, last, current;
bool visited[100009];
vector<int> listt[100009];
map<pair<int, int>, int> idx;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    in[y]++, idx[{x, y}] = i + 1;
    listt[x].push_back(y);
  }
  queue<pair<int, int>> q;
  for (int i = 1; i <= n; i++)
    if (in[i] == 0) q.push({i, 0});
  while (q.size()) {
    if (q.size() > 1) {
      cout << "-1";
      return 0;
    }
    current = q.front().first, last = q.front().second;
    q.pop();
    for (int i = 0; i < listt[current].size(); i++) {
      in[listt[current][i]]--;
      if (in[listt[current][i]] == 0) {
        visited[listt[current][i]] = true;
        last = max(last, idx[{current, listt[current][i]}]);
        q.push({listt[current][i], last});
      }
    }
  }
  cout << last;
  return 0;
}
