def calc_length(node, step)
  @edge[node].each do |next_node|
    if @length[next_node][(step+1)%3] > 0
      next
    else
      @length[next_node][(step+1)%3] = step+1
    end
    @queue.push([next_node, step+1])
  end
end

n, m = gets.chomp.split.map(&:to_i)
@edge = Array.new(n+1){[]} # インデックスの補正
m.times do |_|
  v1, v2 = gets.chomp.split.map(&:to_i)
  @edge[v1].push(v2)
end
s, t = gets.chomp.split.map(&:to_i)

@queue = [[s,0]]
@length = Array.new(n+1) { Array.new(3, 0) }

until @queue.empty?
  #p @length
  node, step = @queue.shift
  if node == t && (step%3 == 0)
    puts step / 3
    exit 0
  end
  
  calc_length(node, step)
end

puts "-1"
