n, m = gets.chomp.split(/ /).map(&:to_i)
arrows = {}

m.times {
  u, v = gets.chomp.split(/ /).map(&:to_i)
  arrows[u] = [] if !arrows[u]
  arrows[u] << v
}

s, t = gets.chomp.split(/ /).map(&:to_i)

current_position = [s]
already_visited = []

# BFS
i = 0
loop {
  i += 1
  current_position -= already_visited
  if current_position.empty?
    puts -1
    exit
  end
  already_visited += current_position

  # けんけんぱ
  3.times { |j|
    current_position = current_position.map { |u| arrows[u] }.flatten.uniq
  }

  if current_position.include?(t)
    puts i
    exit
  end
}
