<?php
// paiza POH! Vol.1
// result:
// http://p...content-available-to-author-only...a.jp/poh/ec-campaign/result/f942b27b8a91fe3f2e0d47adf9302379
// author: Leonardone @ NEETSDKASU
$p = array_fill(0, 1000000, 0);
$nd = explode(" ",fgets(STDIN));
$n = (int)$nd[0];
$d = (int)$nd[1];
do { ++$p[(int)fgets(STDIN)]; } while (--$n);
$p[9] = $p[0] = 1;
do {
	$f = $m = (int)fgets(STDIN);
	$tmp = 0;
	for (;;) {
		--$f;
		while (!$p[$f]) --$f;
		if (($e = $m - $f) > $f) break;
		if ($f == $e) if ($p[$f] == 1)  --$e;
		while (!$p[$e]) --$e;
		if ($e > 9) if (($e += $f) > $tmp) if (($tmp = $e) == $m) break;
	}
	echo $tmp, PHP_EOL;
} while (--$d);
