#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, ans, e[100005][2], vis[100005];
vector<int> v[100005];
stack<int> s;
map<int, int> mp[100005];
void dfs(int node) {
  if (vis[node]) return;
  vis[node] = 1;
  for (int i = 0; i < v[node].size(); i++) {
    dfs(v[node][i]);
  }
  s.push(node);
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    v[x].push_back(y);
    e[i][0] = x;
    e[i][1] = y;
    mp[x][y] = i;
  }
  for (int i = 1; i <= n; i++) {
    dfs(i);
  }
  while (!s.empty()) {
    int node1 = s.top();
    s.pop();
    if (s.empty()) break;
    int node2 = s.top();
    s.pop();
    if (mp[node1].find(node2) == mp[node1].end()) {
      printf("-1");
      return 0;
    } else {
      ans = max(ans, mp[node1][node2]);
    }
    s.push(node2);
  }
  printf("%d", ans);
}
