require 'set'

str = gets.split
N,M = str[0].to_i, str[1].to_i

r = Array.new(N+1){Array.new(3){Set.new}}

for i in 1..M do
    str = gets.split
    u,v = str[0].to_i, str[1].to_i
    r[u][0].add(v)
end

str = gets.split
S,T = str[0].to_i, str[1].to_i

for i in 1..N do
    if r[i][0].size > 0
        r[i][0].each do |val|
            r[i][1].merge(r[val][0])
        end
    end
end
for i in 1..N do
    if r[i][1].size > 0
        r[i][1].each do |val|
            r[i][2].merge(r[val][0])
        end
    end
end

arrive = Set.new
narrive = Set.new
parrive = Set.new
empty = Set.new
arrive.add(S)
narrive.add(S)
answer = 1
while 1 > 0
    if narrive.size > 0
        narrive.each do |val|
            parrive.merge(r[val][2])
        end
    else
        puts -1
        exit
    end
    if parrive.include?(T)
        puts answer
        exit
    else
        narrive = parrive - arrive
        arrive.merge(parrive)
        parrive = parrive & empty
    end
    answer += 1
end