
import std.stdio, std.string, std.array, std.algorithm, std.conv;

int mod_max(int[] arr, int n) {
  int max;
  foreach(i; arr) {
    int k = i % n;
    max = (max < k) ? k : max;
    if (max == n - 1) break;
  }
  return max;
}

void main() {
  for(int n, q; readf("%d %d\n", &n, &q);) {
    int[] arr = readln.chomp.split(" ").map!(to!int).array;
    foreach(t; 0..q) {
      int i;
      readf("%d\n", &i);
      writeln(mod_max(arr, i));
    }
  }
}