{-# LANGUAGE FlexibleContexts #-}

import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import Control.Monad.ST
import qualified Control.Monad.State as State
import Control.Monad
import Control.Applicative
import qualified Data.Set as Set
import qualified Debug.Trace as DT
import qualified Data.Maybe as MB
import qualified Data.List as L

import qualified Data.ByteString.Char8 as BS



data Edge a = Edge {edgeFrom :: Int, edgeTo :: Int, edgeDist :: a} deriving Show
newtype Graph a = Graph (V.Vector [Edge a]) deriving Show

emptyGraph :: Int -> Graph a
emptyGraph n = Graph (V.replicate n [])

constructGraph :: Int -> [Edge a] -> Graph a
constructGraph n edges = runST $ do
  g <- V.thaw $ (\(Graph b) -> b) (emptyGraph n)
  forM edges $ \e@(Edge s t d) -> do
    VM.modify g (e:) s
  return . Graph =<< V.freeze g

dijkstra :: Integral a => Graph a -> Int -> (V.Vector (Maybe a))
dijkstra (Graph graph) src = runST $ do
  ret <- VM.replicate n Nothing
  check <- VM.replicate n False

  let
    loop = do
      isNull <- Set.null <$> State.get

      when (not isNull) $ do
        (dist,cur) <- State.state Set.deleteFindMin

        checked <- State.lift $ VM.read check cur
        State.lift $ VM.write check cur True

        when (not checked) $ do

          forM_ (graph V.! cur) $ \(Edge _ next d) -> do
            a <- State.lift $ VM.read ret next

            if a == Nothing then do
              State.lift $ VM.write ret next (Just $ dist+d)
              State.modify $ Set.insert (dist+d, next)
              
              else do
              let (Just dist') = a

              when (dist + d < dist') $ do
                State.lift $ VM.write ret next (Just $ dist+d)

                (State.lift $ VM.read check next) >>= \b -> do
                  when (not b) $ do
                    State.modify $ Set.insert (dist+d, next)
        loop
      
  VM.write ret src (Just 0)
  State.runStateT loop (Set.singleton (0,src))
  V.freeze ret
  
  where
    n = V.length graph



readInts = map (fst . MB.fromJust . BS.readInt) . BS.words <$> BS.getLine
  
main :: IO ()
main = do
  [n,m] <- readInts :: IO [Int]

  edges <- concat <$> do
    replicateM m $ do
      [u,v] <- readInts :: IO [Int]
      return $ [(Edge (u-1) ((v-1)+n) 1), (Edge ((u-1)+n) ((v-1)+2*n) 1), (Edge ((u-1)+2*n) (v-1) 1)]

  [s,t] <- readInts :: IO [Int]

  let
    g = constructGraph (3*n) edges
    dist = dijkstra g (s-1)

  let ans = dist V.! (t-1)

  print $
    case ans of
      Nothing -> -1
      Just x -> x`div`3  

  return ()
