N, M = gets.split.map(&:to_i)
edges = Array.new(N){[]}
M.times do
    a, b = gets.split.map(&:to_i)
    edges[a-1].push(b-1)
end
S, T = gets.split.map(&:to_i).map(&:pred)

dist = Array.new(N){Array.new(3)}
dist[S][0] = 0
que = [[S, 0]]
while que.size > 0
    i, x = que.shift
    y = (x+1) % 3
    edges[i].each do |j|
        unless dist[j][y]
            dist[j][y] = dist[i][x] + 1
            que.push([j, y])
        end
    end
end

ans = dist[T][0] || -3
puts ans/3