require 'set'
N,M = gets.chomp.split(" ").map(&:to_i)
mat = []
M.times do
    mat << gets.chomp.split(" ").map(&:to_i)
end
S,T = gets.chomp.split(" ").map(&:to_i)

@graph = Array.new(N+1){[]}

# p [N,M]
# p mat
# p [S,T]

mat.each do |arr|
    u = arr[0]
    v = arr[1]
    @graph[u] << v
end
# p @graph
# (1..N).each do |n|

# next1 = []
next1 = Set.new
@graph_2 = Array.new(N+1){Set.new}
(1..N).each do |n|
    @graph[n].each do |s1|
        @graph[s1].each do |s2|
            @graph[s2].each do |s3|
                if n != s3
                    @graph_2[n] << s3
                end
            end
        end
    end
end
# p @graph_2
# next1.each do |n|
#     p n
# end
@visited = Array.new(N+1)
@q = []
@dist = Array.new(N+1)
@dist[S]=0
def bfs(v)
    @visited[v] = true
    @q.push v
    while(tmp = @q.shift) do
        # p tmp
        nodes = @graph_2[tmp]
        nodes.each do |n|
            if not @visited[n]
                @visited[n] = true
                @q.push n
                @dist[n] = @dist[tmp]+1
            end
        end
    end
end

bfs(S)
# p @dist
puts @dist[T] ? @dist[T] : -1