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

next_of = {}
m.times.each{|i| 
    a, b = gets.split.map(&:to_i)
    if not next_of.has_key?(a)
        next_of[a] = Set[]
    end
    next_of[a].add(b)
}
s, t = gets.split.map(&:to_i)

reached = Set[s]
count = 0
current = Set[s]

while !reached.include?(t)
    3.times{|i|
        current = current.map{|it| next_of[it]}.reject{|it| it == nil}.inject(:+)
    }
    if current.subset?(reached)
        count = -1
        break
    end
    reached = reached + current
    current = current - reached
    count += 1
end

puts count