package main
import (
"io"
"os"
"sort"
)
func main() {
buf, _ := io.ReadAll(os.Stdin)
pos := 0
nextInt := func() int {
for pos < len(buf) && buf[pos] <= ' ' {
pos++
}
if pos >= len(buf) {
return 0
}
res := 0
for pos < len(buf) && buf[pos] > ' ' {
res = res*10 + int(buf[pos]-'0')
pos++
}
return res
}
nextInt64 := func() int64 {
for pos < len(buf) && buf[pos] <= ' ' {
pos++
}
if pos >= len(buf) {
return 0
}
var res int64 = 0
for pos < len(buf) && buf[pos] > ' ' {
res = res*10 + int64(buf[pos]-'0')
pos++
}
return res
}
n := nextInt()
q := nextInt()
if n == 0 {
return
}
var maxA int
var S int64
count := make([]int, 1<<20)
for i := 0; i < n; i++ {
val := nextInt()
count[val]++
if val > maxA {
maxA = val
}
S += int64(val)
}
for i := 0; i < 20; i++ {
for mask := (1 << 20) - 1; mask >= 0; mask-- {
if (mask & (1 << i)) == 0 {
count[mask] += count[mask|(1<<i)]
}
}
}
type Pair struct {
cost int64
x int
}
pairs := make([]Pair, 1<<20)
for x := 0; x < (1 << 20); x++ {
var c int64 = 0
for k := 0; k < 20; k++ {
if (x & (1 << k)) != 0 {
m := x & ^((1 << (k + 1)) - 1)
diff := count[m] - count[m|(1<<k)]
if diff == 0 {
continue
}
term1 := int64(diff) * int64(x&((1<<(k+1))-1))
var term2 int64 = 0
for j := 0; j < k; j++ {
cDiff := count[m|(1<<j)] - count[m|(1<<k)|(1<<j)]
term2 += int64(cDiff) << j
}
c += term1 - term2
}
}
pairs[x] = Pair{cost: c, x: x}
}
sort.Slice(pairs, func(i, j int) bool {
return pairs[i].cost < pairs[j].cost
})
maxX := make([]int, 1<<20)
maxVal := 0
for i := 0; i < (1 << 20); i++ {
if pairs[i].x > maxVal {
maxVal = pairs[i].x
}
maxX[i] = maxVal
}
out := make([]byte, 0, 1024*1024)
for i := 0; i < q; i++ {
k := nextInt64()
ans2 := (k + S) / int64(n)
var res int64
if ans2 >= int64(maxA) {
res = ans2
} else {
idx := sort.Search(1<<20, func(j int) bool {
return pairs[j].cost > k
}) - 1
if idx >= 0 {
res = int64(maxX[idx])
} else {
res = 0
}
}
if res == 0 {
out = append(out, '0', '\n')
} else {
var tmp [20]byte
tIdx := 20
for res > 0 {
tIdx--
tmp[tIdx] = byte((res % 10) + '0')
res /= 10
}
out = append(out, tmp[tIdx:]...)
out = append(out, '\n')
}
if len(out) > 500*1024 {
os.Stdout.Write(out)
out = out[:0]
}
}
if len(out) > 0 {
os.Stdout.Write(out)
}
}