object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val V, E = sc.nextInt()
    val G = Array.fill(V + 1)(List[Int]())
    (0 until E) foreach { _ =>
      val u, v = sc.nextInt()
      G(u) ::= v
    }

    def solve(V: Int, E: Int, G: Array[List[Int]]): Option[Set[Int]] = {
      val visited = new Array[Boolean](V+1)
      val cycle = new Array[Boolean](V+1)

      def findCyclic(stack: List[Int]): Boolean =
        if (stack.nonEmpty) {
          val u = stack.head
          if (u > 0) {
            if (cycle(u)) {
              skipWhileStartNode(u, stack.tail)
              true
            } else {
              cycle(u) = true
              visited(u) = true
              findCyclic(G(u).foldRight(-u :: stack.tail)((v, stack) => v :: stack))
            }
          } else {
            cycle(-u) = false
            findCyclic(stack.tail)
          }
        } else false

      def skipWhileStartNode(start: Int, stack: List[Int]): Unit =
        if (stack.nonEmpty) {
          val u = stack.head
          if (-u == start) removeOthers(stack.tail)
          else skipWhileStartNode(start, stack.tail)
        }

      def removeOthers(stack: List[Int]): Unit =
        if (stack.nonEmpty) {
          val u = stack.head
          if (u < 0) cycle(-u) = false
          removeOthers(stack.tail)
        }

      def loop(s: Int): Option[Set[Int]] =
        if (s <= V) {
          if (!visited(s) && findCyclic(s :: Nil)) Some((1 to V) filter cycle toSet)
          else loop(s + 1)
        } else None

      loop(1)
    }

    solve(V, E, G) match {
      case Some(set) => println(set.size); println(set.mkString("\n"))
      case None => println(-1)
    }
  }

}