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)

hop1 = N.times.map{ Set[] }
hop2 = N.times.map{ Set[] }
hop3 = N.times.map{ Set[] }
uvs.each do |u, v|
  hop1[u-1] << v-1
end
hop1.each_with_index do |set, from|
  set.each do |via|
    hop1[via].each do |to|
      hop2[from] << to
    end
  end
end
hop1.each_with_index do |set, from|
  set.each do |via|
    hop2[via].each do |to|
      hop3[from] << to
    end
  end
end

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