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

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 dp = new Array[Boolean](N+1)
  val dp2 = Array.fill[List[Int]](N+1)(Nil)

  val q = new Queue[Info]
  q.enqueue(Info(S, 3, 0))
  dp(S) = true

  var ans = -1
  breakable {
    while(!q.isEmpty) {
      val Info(node, restMove, cnt) = q.dequeue()

      if (restMove == 0) {
        if (!dp(node)) {
          if (node == T) {
            ans = cnt + 1
            break
          }
          else {
            dp(node) = true
            for (e <- graph(node))
              q.enqueue(Info(e, 2, cnt+1))
          }
        }
      }
      else if (!dp2(node).contains(restMove)){
        dp2(node) = restMove :: dp2(node)
        for (e <- graph(node))
          q.enqueue(Info(e, restMove-1, cnt))
      }
    }
  }

  println(ans)
}


case class Info(node: Int, restMove: Int, cnt: Int)

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