import javax.swing.DefaultBoundedRangeModel

import scala.annotation.tailrec

object Main extends App {
  import scala.io.StdIn._

  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val nodes = Array.fill(n){Nil: List[Int]}
  for (_ <- 0 until m) {
    val Array(u, v) = readLine.trim.split(' ').map(_.toInt - 1)
    nodes(u) ::= v
  }
  val Array(s, t) = readLine.trim.split(' ').map(_.toInt - 1)
  val reachable = Array.fill(n){Array.fill(3){-3}}
  reachable(s)(0) = 0
  mark(List(s))
  println(
    reachable(t)(0) / 3
  )
  @tailrec
  def mark(current: List[Int], count: Int = 1): Unit = {
    current match {
      case Nil => ()
      case _ =>
        var next = Nil: List[Int]
        for (c <- current) {
          for (n <- nodes(c) if reachable(n)(count % 3) == -3) {
            reachable(n)(count % 3) = count
            next ::= n
          }
        }
        mark(next, count + 1)
    }
  }
}