#include <bits/stdc++.h>
using namespace std;
int len = 0, coun = 0;
bool visited[1000006];
vector<int> check;
vector<int> grid[1000006];
void dfs(int v) {
  visited[v] = true;
  for (int i = 0; i < grid[v].size(); i++) {
    if (!visited[grid[v][i]]) {
      dfs(grid[v][i]);
    }
  }
  check.push_back(v);
}
void toposort(int n) {
  memset(visited, false, sizeof(visited));
  coun = 0;
  for (int i = 0; i < n; i++) {
    if (!visited[i + 1]) dfs(i + 1);
  }
}
int main() {
  int n, m, x, y;
  cin >> n >> m;
  map<pair<int, int>, int> ma;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    ma[{x, y}] = i;
    grid[x].push_back(y);
  }
  toposort(n);
  reverse(check.begin(), check.end());
  bool ans = true;
  int maxi = 0;
  for (int i = 0; i < check.size() - 1; i++) {
    if (ma.find(make_pair(check[i], check[i + 1])) == ma.end())
      ans = false;
    else
      maxi = max(maxi, ma[make_pair(check[i], check[i + 1])]);
  }
  if (ans == false)
    cout << -1;
  else
    cout << maxi + 1;
}
