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

g = UVs.each_with_object(Hash.new{|h, k| h[k] = []}){|(u, v), h| h[u] << v}
g3 = g.keys.each_with_object(Hash.new{|h, k| h[k] = []}){|u, h| h[u] += g[u].flat_map{|v| g[v]}.uniq.flat_map{|w| g[w]}.uniq}
q = [S]
f = []
while !q.empty?
  x = q.shift
  g3[x].each do |y|
    if y == T
      c, z = 1, 0
      until z == S do
        z = f[x]
        c += 1
      end
      puts c
      exit
    elsif f[y].nil?
      f[y] = x
      q << y
    end
  end
end
puts -1