number_cards, number_questions = gets.split.map do |tmp|
  tmp.to_i
end

cards = []
questions = []

number = gets.split.map do |tmp|
  tmp.to_i
end
number_cards.times.with_index(0) do |i|
  cards << number[i]
end

number_questions.times do
  questions << gets.to_i
end
cards = cards.sort

remainder = []
questions.each do |q|
  last_num = cards[last]
  remainder << last_num % q
  hoge = lastnum - remainder[0]
  cards = cards.select{ |x| hoge > x }
  cards = cards.max

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

  puts remainder.max
end