#include <iostream>
#include <algorithm>

using namespace std;

const int MX = 300001;
bool chck[MX];
int idx[MX];
 
int main()
{
    int n, q, inp, lim;
 
    cin >> n >> q;
    lim = 0;
    while (n--) {
        cin >> inp;
        chck[inp] = true;
        lim = max(lim, inp);
    }
     
    int pre = 0;
    for (int i = 1; i <= lim; i++) {
        if (chck[i]) {
            idx[i] = pre;
            pre = i;
        }
        else
            idx[i] = pre;
    }
         
 
    while (q--) {
        int s = lim;
        int ans = 0;
        cin >> inp;
 
        if (inp > s) 
            cout << s << endl;
        else {
            while (s > 0) {
                ans = max(ans, s % inp);
             
                if (s < inp)
                    break;
                s = idx[s - (s % inp)];
            }
            cout << ans << endl;
        }
    }
 
    return 0;
}