N, M = gets.chomp.split(" ").map(&:to_i)
adj = Array.new(N+1) { Array.new }
M.times do 
    u, v = gets.chomp.split(" ").map(&:to_i)
    adj[u] << v
end
S, T = gets.chomp.split(" ").map(&:to_i)
visited = Array.new(N+1, false)
current_nodes = [S]
next_nodes = []
count = 0
while !current_nodes.empty?
    current_nodes.each do |current_node|
        visited[current_node] = true
        sub_current_nodes = [current_node]
        3.times do 
            sub_next_nodes = []
            sub_current_nodes.each do |sub_current_node|
                sub_next_nodes += adj[sub_current_node]
            end
            sub_current_nodes = sub_next_nodes.uniq
        end
        next_nodes += sub_current_nodes
    end
    current_nodes = next_nodes.uniq.reject{|node| visited[node]}
    count += 1
    if current_nodes.find {|n| n == T}
        puts count 
        exit
    end
end
puts -1