#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> card;

int main(void){
  int N, Q, c, q;
  cin >> N >> Q;
  for(int i = 0; i < N; i++){
    cin >> c;
    card.push_back(c);
  }
  sort(card.begin(), card.end());
  int me = card[N - 1];
  for(int i = 0; i < Q; i++){
    cin >> q;
    int M = -1;
    int u = int(1.0 * me / q + 0.9);
    for(int i = 1; i <= u; i++){
      vector<int>::iterator it = lower_bound(card.begin(), card.end(), q * i);
      if(it != card.begin()) M = max(M, *(it - 1) % q);
    }
    cout << M << endl;
  }
  return 0;
}