import java.util.*

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toInt)
    val edge = Array(n * 3) { mutableSetOf<Int>() }
    for (i in 0 until m) {
        val (u, v) = readLine()!!.split(' ').map(String::toInt)
        edge[(u - 1) * 3].add((v - 1) * 3 + 1)
        edge[(u - 1) * 3 + 1].add((v - 1) * 3 + 2)
        edge[(u - 1) * 3 + 2].add((v - 1) * 3)
    }
    val (s, t) = readLine()!!.split(' ').map(String::toInt)
    val deq = LinkedList<Int>()
    deq.add((s - 1) * 3)
    val deka = 999999998
    val score = Array(3 * n) { deka }
    score[(s - 1) * 3] = 0
    while (deq.isNotEmpty()) {
        val meu = deq.remove()!!
        val meumeu = meu % 3
        edge[meu].forEach {
            if (score[meu] + 1 < score[it]) {
                score[it] = score[meu] + 1
                deq.add(it)
            }
        }
    }
    print(if (score[(t - 1) * 3] % 3 == 0) score[(t - 1) * 3] / 3 else -1)
}
