require 'set'

N, M = gets.chomp.split(" ").map(&:to_i)
E = Hash.new{|h, k| h[k] = []}
M.times{
  u, v = gets.chomp.split(" ").map(&:to_i)
  E[u] << v
}
S, T = gets.chomp.split(" ").map(&:to_i)

def next_step(s)
  ret = []
  s.each{|x|
    ret.concat(E[x])
  }
  ret.uniq
end

past = Set.new
past.add(S)
now_pos = [S]
cnt = 1
ans = -1
while(!now_pos.empty? && ans == -1) do
  step3 = next_step(next_step(next_step(now_pos)))
  now_pos = []
  step3.each{|s|
    (ans = cnt; break) if s == T
    if !past.include?(s) then
      now_pos << s
      past.add(s)
    end
  }
  cnt += 1
end

puts ans
