object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    new Main(out, new InputReader(System.in)).solve()
    out.flush()
  }

  private[this] val oj = System.getenv("ATCODER_DEBUG") == null
  @inline private final def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  @inline private final def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  @inline private final def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  @inline private final def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  @inline private final def debugDim(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  @inline private final def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  @inline private final def debug(s: => String): Unit = DEBUG {
    System.err.println(s)
  }
  @inline private final def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }
  private def isDebug[A](debug: => A, online: => A): A = {
    if (oj) online else debug
  }

  class InputReader(val stream: InputStream) {
    private[this] val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()
    def nl(): Long = nextLong()
    def nc(): Char = nextChar()
    def ns(): String = next()
    def ns(n: Int): Array[Char] = ns().toCharArray
    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }
    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }
    def nal(n: Int): Array[Long] = map(n)(_ => nl())
    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  }

  @inline private final def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  @inline private final def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }
  @inline private final def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }
  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }
  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer

  // toIntとか+7とかするならvalにしろ
  final private[this] val MOD = 1000000007

  def packDGraph(n: Int, from: Array[Int], to: Array[Int]): Array[Array[Int]] = {
    val t = new Array[Array[Int]](n)
    val p = new Array[Int](n)
    val m = from.length
    REP(m)(i => p(from(i)) += 1)
    REP(n)(i => t(i) = new Array(p(i)))
    REP_r(m) { i => // 順序維持する
      p(from(i)) -= 1
      t(from(i))(p(from(i))) = to(i)
    }
    t
  }
  def findCycle(n: Int, g: Array[Array[Int]]): Option[Array[Int]] = {
    val flag = Array.ofDim[Int](n)
    val ix = Array.ofDim[Int](n)
    val q = Array.ofDim[Int](n)

    def dfs(i: Int): Option[Array[Int]] = {
      def step(last: Int): Option[Array[Int]] =
        if (last < 0) None
        else {
          val v = q(last)

          flag(v) match {
            case 2 => step(last - 1)

            case 0 | 1 =>
              flag(v) = 1
              if (g(v).length == ix(v)) { // vの探索終わり
                flag(v) = 2
                step(last - 1)
              } else {  // dfs(u)
                val u = g(v)(ix(v))
                ix(v) += 1
                val next = last + 1
                flag(u) match {
                  case 0 =>
                    q(next) = u
                    step(next)

                  case 1 => // 閉路見つかった
                    val found = q.indexOf(u)
                    Some(java.util.Arrays.copyOfRange(q, found, next))

                  case _ => step(last)
                }
              }
          }
        }

      q(0) = i
      step(0)
    }

    def step(i: Int): Option[Array[Int]] =
      if (i == n) None
      else {
        if (flag(i) != 0) step(i + 1)
        else dfs(i) match {
          case None => step(i + 1)
          case Some(cycle) => Some(cycle)
        }
      }

    step(0)
  }
  def solve(): Unit = {
    val n, m = ni()
    val (a, b) = na2(m, -1)
    val g = packDGraph(n, a, b)
    val revE = Array.ofDim[Int](n, n)
    REP(m) { i =>
      revE(a(i))(b(i)) = i
    }

    def traceNewCycle(s: Int, t: Int, cycle: ArrayBuffer[Int]) = {
      val res = ArrayBuffer[Int]()
      res += s
      var i = cycle.indexOf(s)
      while(res.last != t) {
        i = (i + 1) % cycle.length
        res += cycle(i)
      }
      res
    }

    val vs = Array.ofDim[Boolean](n)
    val ps = Array.ofDim[Boolean](m)
    def decreaseUntilAnswer(cycle: ArrayBuffer[Int]): ArrayBuffer[Int] = {
      import java.util
      util.Arrays.fill(vs, false)
      util.Arrays.fill(ps, false)
      REP(cycle.length) { i =>
        vs(cycle(i)) = true
      }
      REP(cycle.length - 1) { i =>
        ps(revE(cycle(i))(cycle(i + 1)))= true
      }
      ps(revE(cycle.last)(cycle.head)) = true
      var end = false
      var i = 0
      while(!end && i < m) {
        if (vs(a(i)) && vs(b(i)) && !ps((revE(a(i))(b(i))))) {
          end = true
        }
        if (!end) i += 1
      }
      if (end) {
        val newCycle = traceNewCycle(b(i), a(i), cycle)
        decreaseUntilAnswer(newCycle)
      } else {
        cycle
      }
    }

    findCycle(n, g) match {
      case Some(cycle) =>
        val ans = decreaseUntilAnswer(ArrayBuffer(cycle: _*))
        out.println(ans.length)
        ans.map(_+1).foreach(out.println)

      case None =>
        out.println(-1)
    }

  }
}

Measured memory_bytes: 32424