object Main extends App {
  import scala.io.StdIn._

  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val down = Array.tabulate(n){_ ⇒ Nil: List[Int]}
  val up = Array.tabulate(n){_ ⇒ Nil: List[Int]}
  val downCount = Array.tabulate(n){_ ⇒ 0}
  val upCount = Array.tabulate(n){_ ⇒ 0}
  val longestDownPath = Array.tabulate(n){i ⇒ Path(i, 0)}
  val longestUpPath = Array.tabulate(n){i ⇒ Path(i, 0)}
  val edges = Array.tabulate(m){_ ⇒
    val Array(a, b) = readLine.trim.split(' ').map(_.toInt - 1)
    Edge(a, b)
  }
  for (Edge(a, b) ← edges){
    down(a) ::= b
    downCount(a) += 1
    up(b) ::= a
    upCount(b) += 1
  }
  var toUp: Seq[Int] = down.indices.filter(downCount(_) == 0)
  while(toUp.nonEmpty){
    var next = Nil: List[Int]
    toUp.foreach{ d ⇒
      for (u ← up(d)) {
        downCount(u) -= 1
        if (downCount(u) == 0) {
          longestDownPath(u).append(longestDownPath(d))
          next ::= u
        }
      }
    }
    toUp = next
  }
  var toDown: Seq[Int] = up.indices.filter(upCount(_) == 0)
  while(toDown.nonEmpty){
    var next = Nil: List[Int]
    toDown.foreach{u ⇒
      for (d ← down(u)){
        upCount(d) -= 1
        if (upCount(d) == 0){
          longestUpPath(d).append(longestUpPath(u))
          next ::= d
        }
      }
    }
    toDown = next
  }
  val currentMax = longestDownPath.maxBy(_.length).length
  val fromDownLength = Array.tabulate(currentMax + 1){_ ⇒ 0}
  for (p ← 0 until n if longestDownPath(p).length + longestUpPath(p).length == currentMax){
    fromDownLength(longestDownPath(p).length) += 1
  }
  val bottleNeck = edges.indices.filter{i ⇒
    val Edge(u, d) = edges(i)
    longestDownPath(u).length == longestDownPath(d).length + 1 &&
    longestDownPath(u).length + longestUpPath(u).length == currentMax &&
      longestDownPath(d).length + longestUpPath(d).length == currentMax &&
      fromDownLength(longestDownPath(u).length) == 1 &&
      fromDownLength(longestDownPath(d).length) == 1
  }
  if (bottleNeck.isEmpty) println(-1)
  else println(bottleNeck.map(_ + 1).mkString("\n"))



  case class Path(current: Int, var length: Int, var from: List[Int] = Nil) {
    def append(path: Path): Unit = {
      if (length < path.length + 1){
        length = path.length + 1
        from = List(path.current)
      }else if (length == path.length + 1){
        from ::= path.current
      }
    }
  }
  case class Edge(from: Int, to: Int)
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline def let[A](@inline func: T ⇒ A): A = func(value)
  }

}
