fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val to = Array<MutableList<Int>>(N, { mutableListOf() } )
    repeat(M) {
        val (u, v) = listOfInt()
        to[u - 1].add(v - 1)
    }
    val (S, T) = listOfInt()
    val INF = 1001001001
    var dist = Array<Array<Int>>(100005) { Array<Int>(3, { INF }) }

    var q = Queue<Pair<Int, Int>>()
    q.enqueue(Pair(S - 1, 0))
    dist[S - 1][0] = 0
    while (!q.isEmpty()) {
        val e = q.dequeue()!!
        val v = e.first
        val l = e.second
        to[v].forEach {
            val nl = (l + 1) % 3
            if (dist[it][nl] == INF) {
                dist[it][nl] = dist[v][l] + 1
                q.enqueue(Pair(it, nl))
            }
        }
    }
    var ans = dist[T - 1][0]
    if (ans == INF) ans = -1 else ans /= 3
    println(ans)
}

class Queue<T> {
    val elements: MutableList<T> = mutableListOf()
    fun isEmpty() = elements.isEmpty()
    fun count() = elements.size
    fun enqueue(item: T) = elements.add(item)
    fun dequeue() = if (!isEmpty()) elements.removeAt(0) else null
    fun peek() = if (!isEmpty()) elements[0] else null
    override fun toString(): String = elements.toString()
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
