fun main(args: Array<String>) {
    val (n, m) = readInputLine().split(" ").map {it.toInt()}
    
    val graph = mutableMapOf<Int, MutableList<Int>>()
    
    for (i in 1..m) {
        val (u, v) = readInputLine().split(" ").map {it.toInt()}
        val edge = graph.get(u) ?: mutableListOf<Int>()
        edge.add(v)
        graph.put(u, edge)
    }
    
    val (s, t) = readInputLine().split(" ").map {it.toInt()}
    
    val alreadyNodes = mutableSetOf<Int>(s)
    var nowNodes = setOf<Int>(s)
    
    var cnt = 0
    
    while (!nowNodes.contains(t)) {
        if (nowNodes.none()) {
            println(-1)
            return
        }
    
        val firstStep = mutableSetOf<Int>()
        
        nowNodes.forEach { firstStep.addAll(graph.get(it) ?: listOf<Int>()) }

        val secondStep = mutableSetOf<Int>()
        
        firstStep.forEach { secondStep.addAll(graph.get(it) ?: listOf<Int>()) }
        
        val thirdStep = mutableSetOf<Int>()
        
        secondStep.forEach { thirdStep.addAll(graph.get(it) ?: listOf<Int>()) }
        
        nowNodes = thirdStep.minus(alreadyNodes)
        alreadyNodes.addAll(nowNodes)
        cnt++
    }

    println(cnt)
}

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