#include <bits/stdc++.h>
using namespace std;
int n, m;
const int MAX = 1e5 + 7;
vector<pair<int, int> > adj[MAX];
bool visited[MAX];
vector<int> st;
void dfs(int i) {
  visited[i] = true;
  for (auto j : adj[i])
    if (!visited[j.second]) dfs(j.second);
  st.push_back(i);
}
int func() {
  for (int i = 1; i <= n; i++)
    if (!visited[i]) dfs(i);
  reverse(st.begin(), st.end());
  int ans = -1;
  for (int i = 0; i < st.size() - 1; i++) {
    bool f = false;
    for (auto j : adj[st[i]])
      if (j.second == st[i + 1]) ans = max(ans, j.first), f = true;
    if (!f) return -1;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(make_pair(i, v));
  }
  cout << func() << endl;
  return 0;
}
