val MaxNodes = 1000
val NewState = 1
val ActiveState = 2
val FinishState = 3
val nodeStatus = IntArray(MaxNodes, { NewState })
val edges = Array(MaxNodes) { mutableSetOf<Int>() }

fun main(args: Array<String>) {
    val (N, M) = readInputLine().split(" ").map { it.toInt() }

    for (i in 1..M) {
        val (A, B) = readInputLine().split(" ").map { it.toInt()  - 1 }
        edges[A].add(B)
    }

    var ret = existsCycle()

    if (!ret.first) {
        println(-1)
        return
    }
    
    ret.third.reverse()
    
    while (true) {
        // 次数チェック
        var routeArr = ret.third.toIntArray()
        
        var ok = true
        var unUsedStart = -1
        var unUsedEnd = -1
        for ((i, n) in routeArr.withIndex()) {
            val intersect = ret.third.intersect(edges[n])
            if (intersect.size != 1) {
                ok = false
                for (e in intersect) {
                    if (routeArr[(i + 1) % ret.third.size] != e) {
                        unUsedStart = n
                        unUsedEnd = e
                        break
                    }
                }
                break
            }
        }
        if (ok) {
            println(ret.third.size)
            for (n in ret.third) {
                println(n + 1)
            }
            return
        }

        // 余分なノードを除去
        val visited = mutableListOf(unUsedEnd)
        var current = edges[unUsedEnd].find { ret.third.contains(it) }!!
        while (current != unUsedStart) {
            visited.add(current)
            current = edges[current].find { ret.third.contains(it) }!!
        }
        visited.add(unUsedStart)
        ret = ret.copy(third = visited)
    }
}

fun readInputLine(): String {
    return readLine()!!
}

fun existsCycle(): Triple<Boolean, Boolean, MutableList<Int>> {
    for (v in 0 until MaxNodes) {
        if (nodeStatus[v] == NewState) {
            val ret = existsCycleSub(v)
            if (ret.first) {
                return ret
            }
        }
    }
 
    return Triple(false, false, mutableListOf<Int>())
}
 
fun existsCycleSub(source: Int): Triple<Boolean, Boolean, MutableList<Int>> {
    nodeStatus[source] = ActiveState
    
    for (e in edges[source]) {
        if (nodeStatus[e] == ActiveState) {
            return Triple(true, false, mutableListOf(e, source))
        } else if (nodeStatus[e] == NewState) {
            val ret = existsCycleSub(e)
            if (ret.first) {
                if (ret.second) {
                    return ret
                }
                if (ret.third.contains(source)) {
                    return ret.copy(second = true)
                }
                ret.third.add(source)
                return ret
            }
        }
    }
    nodeStatus[source] = FinishState

    return Triple(false, false, mutableListOf<Int>())
}
