module PQ = Set.Make(struct type t = int * int * int let compare = compare end)
let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let g = Array.init n (fun _ -> []) in
  for _ = 1 to m do
    Scanf.scanf " %d %d" @@ fun u v ->
    g.(u-1) <- v-1 :: g.(u-1);
  done;
  Scanf.scanf " %d %d" @@ fun s t ->
  let s, t = s-1, t-1 in
  let dist = Array.init 3 (fun _ -> Array.make n (max_int / 3)) in
  let rec loop pq =
    if PQ.is_empty pq then () else
    let d,x,m = PQ.min_elt pq in
    let pq = PQ.remove (d,x,m) pq in
    if d > dist.(m).(x) then loop pq else begin
      let m = (m+1) mod 3 in
      List.fold_left (fun pq y -> 
        if d+1 >= dist.(m).(y) then pq else begin
          dist.(m).(y) <- d+1;
          PQ.add (d+1, y, m) pq
        end
      ) pq g.(x) |> loop
    end
  in
  loop PQ.(singleton (0, s, 0));
  if dist.(0).(t) < max_int/3 then Printf.printf "%d\n" (dist.(0).(t) / 3)
  else print_endline "-1"
