N, M = gets.chomp.split(' ').map(&:to_i)
GN = M.times.map {
  gets.chomp.split(' ').map(&:to_i)
}
S, T = gets.chomp.split(' ').map(&:to_i)

GH = {}
GN.each do |g|
  GH[g[0]] = [] unless GH.key?(g[0])
  GH[g[0]].push(g[1])
end

points = [S]
1.upto(1000000) do |count|
  start = points
  3.times do
    points = points.reduce([]) {|p, i|
      p.concat(GH[i]) if GH.key?(i)
      p
    }.uniq
  end
  start.each { |s| points.delete(s) }
  
  if points.empty?
    puts -1
    break
  end

  if points.include?(T)
    puts count
    break
  end

  if 1000000 == count
    puts -1
  end
end
