#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const long long MOD = 1e9 + 9;
bool isPrime(long long x) {
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return false;
  return true;
}
double dist(double a, double b, double c, double d) {
  return sqrt((c - a) * (c - a) + (d - b) * (d - b));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  srand(time(0));
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n + 1);
  vector<int> in_deg(n + 1), dis(n + 1);
  vector<pair<int, int>> edges;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    edges.push_back({a, b});
    g[a].push_back(b);
    in_deg[b]++;
  }
  for (int i = 0; i < n; i++) {
    g[n].push_back(i);
    in_deg[i]++;
  }
  function<void(int)> dfs = [&](int u) {
    for (auto v : g[u]) {
      dis[v] = max(dis[v], dis[u] + 1);
      in_deg[v]--;
      if (in_deg[v] == 0) {
        dfs(v);
      }
    }
  };
  dfs(n);
  int ans = 0, x;
  bool done = 0;
  for (int i = 0; i < n; i++) {
    if (dis[i] == n) {
      done = 1;
      x = i;
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    dis[i]--;
  }
  map<pair<int, int>, bool> mp;
  function<void(int, int)> path = [&](int u, int d) {
    for (auto v : g[u]) {
      if (dis[v] == d - 1) {
        mp[{v, u}] = 1;
        path(v, dis[v]);
      }
    }
  };
  if (done) {
    g.clear();
    g.resize(n);
    for (int i = 0; i < m; i++) {
      g[edges[i].second].push_back(edges[i].first);
    }
    path(x, n - 1);
    for (int i = 0; i < m; i++) {
      mp.erase(edges[i]);
      if (mp.size() == 0) {
        ans = i + 1;
        break;
      }
    }
    cout << ans;
  } else {
    cout << "-1";
  }
  return 0;
}
