import java.util.*

data class Edge(val from: Int, val to: Int)

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val graph = Array(3 * n, { mutableListOf<Edge>() })
    repeat(m) {
        val (v1Raw, v2Raw) = readLine()!!.split(" ").map { it.toInt() }
        val v1 = v1Raw - 1
        val v2 = v2Raw - 1
        graph[v1].add(Edge(v1, n + v2))
        graph[n + v1].add(Edge(n + v1, 2 * n + v2))
        graph[2 * n + v1].add(Edge(2 * n + v1, v2))
    }
    val (sRaw, tRaw) = readLine()!!.split(" ").map { it.toInt() }
    val s = sRaw - 1
    val t = tRaw - 1

    val queue = ArrayDeque<Int>()
    val visited = BooleanArray(3 * n)
    val dists = IntArray(3 * n, { -1 })
    queue.offerLast(s)
    dists[s] = 0
    visited[s] = true
    while (queue.isNotEmpty()) {
        val v = queue.pollFirst()
        for (e in graph[v]) {
            val u = e.to
            if (visited[u]) continue
            dists[u] = dists[v] + 1
            visited[u] = true
            queue.offerLast(u)
        }
    }

    if (dists[t] == -1) {
        println(-1)
    } else {
        println(dists[t] / 3)
    }
}