n,m = gets.chomp.split(" ").map(&:to_i)
step1 = Array.new(n).map{Array.new()}
for i in 1..m do
    u,v = gets.chomp.split(" ").map(&:to_i)
    step1[u-1].push(v)
end
s,t = gets.chomp.split(" ").map(&:to_i)

step2 = Array.new(n).map{Array.new()}
for i in 1..n do
    for j in step1[i-1]
        step2[i-1].concat(step1[j-1])
    end
    step2[i-1].uniq!
end

step3 = Array.new(n).map{Array.new()}
for i in 1..n do
    for j in step2[i-1]
        step3[i-1].concat(step1[j-1])
    end
    step3[i-1].uniq!
end

find = false
stack = [[s,0]]
check = 2**n -1
while !stack.empty? && !find
    tar = stack.shift
        check &= ~(2**(tar[0]-1))
        for i in step3[tar[0]-1]
            if i == t 
                puts tar[1]+1
                find = true
            elsif check[i-1] == 1
                check &= ~(2**(i-1))
                stack.push([i,tar[1]+1])
            end
        end
end

if !find
    puts "-1"
end