#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y) {
  long long int res = 1;
  while (y) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y / 2, x = (x * x) % 1000000007;
  }
  return res % 1000000007;
}
vector<vector<long long int> > graph;
long long int visited[100001];
long long int indeg[100001];
long long int n;
bool func() {
  queue<long long int> q;
  long long int vis[100001] = {0};
  long long int i;
  for (i = 1; i <= n; i++)
    if (indeg[i] == 0) q.push(i);
  if (q.size() != 1) return false;
  while (!q.empty()) {
    long long int k = q.front();
    vis[k] = 1;
    q.pop();
    for (auto v : graph[k]) {
      indeg[v]--;
      if (indeg[v] == 0) {
        q.push(v);
      }
    }
    if (q.size() > 1) return false;
  }
  for (i = 1; i <= n; i++)
    if (!vis[i]) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int m;
  cin >> n >> m;
  long long int arr[m + 1][2];
  long long int i;
  for (i = 1; i <= m; i++) {
    cin >> arr[i][0] >> arr[i][1];
  }
  long long int low = 1, high = m;
  long long int ans = -1;
  while (low <= high) {
    long long int mid = (low + high) / 2;
    graph.resize(n + 1);
    for (i = 0; i <= n; i++) graph[i].clear(), indeg[i] = 0, visited[i] = 0;
    long long int cnt = 0;
    for (i = 1; i <= mid; i++) {
      graph[arr[i][0]].push_back(arr[i][1]);
      indeg[arr[i][1]]++;
      if (visited[arr[i][0]] == 0) {
        visited[arr[i][0]] = 1;
        cnt++;
      }
      if (visited[arr[i][1]] == 0) {
        visited[arr[i][1]] = 1;
        cnt++;
      }
    }
    if (cnt != n) {
      low = mid + 1;
      continue;
    }
    if (func()) {
      ans = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }
  cout << ans;
}
