N, M = gets.split.map(&:to_i)
ways = M.times.map { gets.split.map(&:to_i) }
start, goal = gets.split.map(&:to_i)

history = [start]
already_visits = Array.new(N + 1, false)
already_visits[start] = true

counter = 0
success_cost = -1
while !history.empty?
  3.times do
    next_history = []
    history.map do |now_place|
      target_ways = ways.select { |k, _v| k == now_place }
      target_ways.each do |target_way|
        next_history << target_way[1]
      end
    end
    history = next_history.uniq
  end
  history = history.reject do |place|
    already_visits[place]
  end
  history.each do |place|
    already_visits[place] = true
  end

  counter += 1
  if history.include?(goal)
    success_cost = counter
    break
  end
end

p success_cost