number_cards, number_questions = gets.split.map{ |i|
  i.to_i
}

cards = gets.split.map{ |i|
  i.to_i
}

number_questions.times do
  questions << gets.to_i
end


questions.each do |q|
  remainder = cards.map do |c|
    c % q
  end

  max_num << remainder.max
end

max_num.each do |num|
  puts num
end