#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
void add(long long &x, long long y) {
  x += y;
  if (x >= MOD) x -= MOD;
  if (x < 0) x += MOD;
}
const long long mxN = 1e5 + 10;
vector<pair<long long, long long> > edge(mxN);
long long n;
vector<long long> topo;
vector<bool> vis(mxN, false);
vector<vector<long long> > adj(mxN);
long long ans = 0;
vector<long long> ind(mxN, 0);
void dfs(long long i) {
  vis[i] = true;
  for (auto u : adj[i]) {
    if (!vis[u]) {
      dfs(u);
    }
  }
  topo.push_back(i);
}
void solve() {
  cin >> n;
  long long e;
  cin >> e;
  for (long long i = 0; i < e; i++) {
    long long x, y;
    cin >> x >> y;
    x--;
    y--;
    ind[y]++;
    edge[i] = {x, y};
    adj[x].push_back(y);
  }
  long long start;
  long long tot = 0;
  for (long long i = 0; i < n; ++i) {
    if (ind[i] == 0) {
      tot++;
      start = i;
    }
  }
  if (tot > 1) {
    cout << -1 << '\n';
    return;
  }
  dfs(start);
  reverse(topo.begin(), topo.end());
  set<pair<long long, long long> > st;
  ;
  for (long long i = 1; i < ((long long)(topo.size())); i++) {
    st.insert({topo[i - 1], topo[i]});
  };
  for (long long i = 0; i < e; ++i) {
    if (st.count({edge[i].first, edge[i].second}))
      st.erase({edge[i].first, edge[i].second});
    if (((long long)(st.size())) == 0) {
      cout << i + 1 << " ";
      return;
    }
  }
  cout << -1 << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(12);
  long long T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
