n, m = gets.split.map(&:to_i)

edge = Array.new(n+1) {[]}
m.times do
    u, v = gets.split.map(&:to_i)
    edge[u] << v
end

s, t = gets.split.map(&:to_i)

visit = Array.new(n+1){Array.new(3)}
visit[s][0] = 0
que = [[s, 0]]

while x = que.shift
    now, x = x
    y = (x + 1) % 3

    edge[now].each do |z|
        next if visit[z][y]
        visit[z][y] = visit[now][x] + 1
        que << [z, y]
    end
end

puts visit[t][0] ? visit[t][0] / 3 : -1