/* paiza POH! Vol.1
 * result:
 * http://p...content-available-to-author-only...a.jp/poh/ec-campaign/result/eaff529ae4d6a00ebf3f808dbe80ab31
 * author: Leonardone @ NEETSDKASU
 */
#include <stdio.h>
#include <stdlib.h>
#define PMAX (1000000)
#define PC(c) putchar(c)
#define PD(d) printf("%d\n", d)
#define PS(s) printf("%s\n", s)
#define SUMCHECK(tmp, sum, i, u, m) \
	sum = i + u; \
	if (sum > tmp) { \
		tmp = sum; \
		if (tmp == m) break; \
	}

int list[PMAX + 1] = {0};
char str[10] = {'\n'};

inline int gc(void) {
    register int c, n = 0;
    do {
        c = getchar();
    } while ((c < '0') || (c > '9'));
    do {
        n = n * 10 + (c - '0');
        c = getchar();
    } while ((c >= '0') && (c <= '9'));
    return n;
}

inline void pi(register int n) {
	register int t, i = 1;
	do {
		t = n / 10;
		str[i] = n - t * 10 + '0';
		++i; n = t;
	} while (n > 0);
	do {
		PC(str[--i]);
	} while (i);
}

int main(void) {
    register int j, i, u, sum, tmp;
    int n, d, m, p;
    
    n = gc();
    d = gc();
    
    j = n + 1;
    while (--j) {
        ++list[gc()];
    }
    
    ++list[9];
    j = d + 1;
    while (--j) {
        i = m = gc();
        tmp = 0;
		do {
			--i;
			while(!list[i]) --i;
			if ((u = m - i) > i) break;
			if (u > 9) {
				if (i == u) {
					if (list[i] > 1) {
						SUMCHECK(tmp, sum, i, u, m);
					} else {
						--u;
						while (!list[u]) --u;
						if (u > 9) {
							SUMCHECK(tmp, sum, i, u, m);
						}
					}
				} else {
					while (!list[u]) --u;
					if (u > 9) {
						SUMCHECK(tmp, sum, i, u, m);
					}
				}
			}
        } while (1);
        pi(tmp);
    }
	
    return 0;
}

