/**
 * Created by hiroqn on 13/10/05.
 */

var fs = require('fs'),
    length = fs.fstatSync(process.stdin.fd).size,
    buffer = new Buffer(length),
    bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
    input = buffer.toString('utf8', 0, bytesRead).split('\n');


function pickGraph(g, edge) {
  var a = edge[0],
      b = edge[1],
      g2 = g.slice();
  (g2[a] = g[a].slice()).splice(g[a].indexOf(b), 1);
  return g2;
}

//dp
function getNumRoom(g, nodeList) {
  var d = [], i, j, node, len, len2, max = 1;
  for (i = 0, len = nodeList.length; i < len; i++) {
    d[nodeList[i]] = 1;
  }
  for (i = 0, len = nodeList.length; i < len; i++) {
    node = nodeList[i];
//    d[i]++;
    for (j = 0, len2 = g[node].length; j < len2; j++) {
      d[g[node][j]] = Math.max(d[g[node][j]], d[node] + 1);
//      d[g[node][j]] = Math.max(d[g[node][j]], d[node] + 1);

    }
    max = Math.max(max, d[node]);
  }
//  console.log(d)
  return max;
}


var temp = input.shift().split(' '),
    n = temp[0],
    m = temp[1],
    edges = [],
    graph,
    i, a, b;
var UF = function () {//union find
  var i,
      par = [];
  for (i = 0; i < n; i++) {
    par[i] = -1;
  }
  function union(x, y) {
    x = find(x);
    y = find(y);
    if (x !== y) {
      if (par[x] < par[y]) {
        par[x] += par[y];
        par[y] = x;
      } else {
        par[y] += par[x];
        par[x] = y;
      }
    }
    return x !== y;
  }

  function find(x) {
    return par[x] < 0 ? x : par[x] = find(par[x]);
  }

  function getNodeListGroup() {
    var k = 0, i, j,
        nodesListGroup = [];
    for (i = 0; i < n; i++) {
      if (par[i] < 0) {
        nodesListGroup[k] = [];
        for (j = 0; j < n; j++) {
          if (i === find(j)) {
            nodesListGroup[k].push(j);
          }
        }
        k++;
      }
//      nodesListGroup[find(i)].push(i);
    }
//    console.log(nodesListGroup)
//    console.log(par)
//    nodesListGroup = nodesListGroup.filter(function (e, i) {
//      return e.length > 0;
//    }).map(function (e) {
//          return e.sort();
//        });
    return nodesListGroup;
  }

  return {
    union: union,
    find: find,
    getNodeListGroup: getNodeListGroup
  };
}();
//make graph and unnion find
var g = [],
    testList = [];
for (i = 0; i < n; i++) {
  testList[i] = i;
  g[i] = [];
}

for (i = 0; i < m; i++) {
  temp = input[i].split(' ');
  a = temp[0] - 1;
  b = temp[1] - 1;
  edges[i] = [a, b];//edges
  g[a].push(b); // make graph
  UF.union(a, b);// union find
}


var nodeListGroup = UF.getNodeListGroup();
//console.log(nodeListGroup);

var numRoomList = nodeListGroup.map(function (nodeList) {//number room group
  return getNumRoom(g, nodeList);
});
//console.log(numRoomList)
var maxNum = Math.max.apply(null, numRoomList),
    index = numRoomList.indexOf(maxNum),
    flag = true,
    nodeList = nodeListGroup[index];

//console.log(nodeList)
if (~numRoomList.slice(index + 1).indexOf(maxNum)) {
  console.log(-1);
  return;
}
if (maxNum !== getNumRoom(g, testList)) {
  throw new Error();
}
for (i = 0; i < m; i++) {
  if (~nodeList.indexOf(edges[i][0])) {
    graph = pickGraph(g, edges[i]);

    if (getNumRoom(graph, nodeList) < maxNum) {
      console.log(i + 1);
      flag = false;
    }
  }
}
if (flag) {
  console.log(-1);
}
return;
flag = true;
for (i = 0; i < m; i++) {
//  console.log(edges[i][0]);
  graph = pickGraph(g, edges[i]);

  if (getNumRoom(graph, nodeList) < maxNum) {
    console.log(i + 1);
    flag = false;
  }
}
//for (i = 0; i < m; i++) {
////  console.log(edges[i][0]);
//  if (~nodeList.indexOf(edges[i][0])) {
//    graph = pickGraph(g, edges[i]);
//
//    if (getNumRoom(graph, nodeList) < maxNum) {
//      console.log(i + 1);
//      flag = false;
//    }
//  }
//}


//for (i = 0; i < edges2.length; i++) {
//  graph = pickGraph(g, edges2[i]);
//  console.log(graph)
//  if (getNumRoom(graph, nodeList) < maxNum) {
//    console.log(i + 1);
//    flag = false;
//  }
//}
if (flag) {
  console.log(-1);
}