require 'set'
N, M = gets.split.map(&:to_i)
uvs = M.times.map{ gets.split.map(&:to_i) }
S, T = gets.split.map(&:to_i)

onehop = N.times.map{ Set[] }
uvs.each do |u, v|
  onehop[u-1] << v-1
end

threehop = onehop.map.with_index do |hop1, me|
  hop1
    .map{|i| onehop[i].to_a }
    .flatten
    .map{|i| onehop[i].to_a }
    .flatten
    .select{|i| i != me }
    .to_set
end

available = Set[]
distance = []
distance[S-1] = 0
queue = [S-1]
loop do
  if queue.size == 0
    puts -1
    exit
  end
  current = queue.pop
  threehop[current].each do |i|
    if i == T-1
      puts distance[current] + 1
      exit
    end
    already_approached = available.include?(i)
    shorter_path = (distance[i] || 9999999) > distance[current] + 1
    next if already_approached && !shorter_path
    queue << i
    available << i
    distance[i] = distance[current] + 1
  end
end
