import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, M = in.next().toInt
  val graph = Array.fill[List[Int]](N+1)(Nil)
  for (_ <- 1 to M) {
    val u, v = in.next().toInt
    graph(u) = v :: graph(u)
  }
  val S, T = in.next().toInt

  //
  val q = new Queue[(Int, Int)]() // (moveNum, node)
  val dp = new Array[Boolean](N+1)

  q.enqueue((0, S))

  var ans = -1
  breakable {
    while (!q.isEmpty) {
      val (cost, now) = q.dequeue

      if (now == T) {
        ans = cost
        break
      }

      dp(now) = true
      var set = Set[Int]()
      set += now

      for (i <- 0 to 3) {
        val nextSet = Set[Int]()
        for (e <- set) {
          if (i == 3) {
            if (!dp(e)) {
              q.enqueue((cost+1, e))
              dp(e) = true
            }
          }
          else {
            for (e2 <- graph(e))
              nextSet += e2
          }
        }

        set = nextSet
      }
    }
  }

  println(ans)

}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
