require 'set'
N, M = gets.chomp.split(" ").map(&:to_i)
adj = Array.new(N+1) { Set.new }
M.times do 
    u, v = gets.chomp.split(" ").map(&:to_i)
    adj[u] << v
end
S, T = gets.chomp.split(" ").map(&:to_i)

adj_by_3 = Array.new(N+1) { Set.new }
adj_by_2 = Array.new(N+1) { Set.new }

for i in 1..N
    adj[i].each do |n|
        adj_by_2[i] += adj[n]
    end
end

for i in 1..N
    adj_by_2[i].each do |n|
        adj_by_3[i] += adj[n]
    end
end

visited = Array.new(N+1, false)
current_nodes = [S]
next_nodes = []
count = 0
while !current_nodes.empty?
    current_nodes.each do |current_node|
        next_nodes += adj_by_3[current_node]
    end
    current_nodes = next_nodes
    count += 1
    if current_nodes.find {|n| n == T}
        puts count 
        exit
    end
end
puts -1