module S = Set.Make (struct type t = int let compare = compare end)

let () =
    let main () =
        let n, m = Scanf.sscanf (read_line ()) "%d %d" (fun n m -> n, m) in
        let uv = Array.init m (fun _ -> Scanf.sscanf (read_line ()) "%d %d" (fun u v -> u, v)) in
        let s, t = Scanf.sscanf (read_line ()) "%d %d" (fun s t -> s, t) in
        let u = Array.make (n + 1) S.empty in
        Array.iter (fun (uu, vv) -> u.(uu) <- S.add vv u.(uu)) uv;
        let visited = Array.make_matrix 3 (n + 1) (-1) in
        visited.(0).(s) <- 0;
        let rec loop step frontier =
            if S.cardinal frontier = 0 then (-1) else
                let curs  = step mod 3 in
                let frontier =
                    S.fold (fun e next_frontier ->
                        S.fold (fun f next_frontier ->
                            if visited.(curs).(f) >= 0 then next_frontier else (
                                visited.(curs).(f) <- step;
                                S.add f next_frontier
                            )
                        ) u.(e) next_frontier
                    ) frontier S.empty
                in
                if visited.(0).(t) >= 0 then visited.(0).(t) / 3 else loop (step + 1) frontier
        in
        let result = loop 1 (S.singleton s) in
        Printf.printf "%d\n" result
    in
    main ()