Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. It is guaranteed that all the values are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$).

Polycarp wants to know answers on $q$ queries. The $j$-th query is described as integer number $b_j$. The answer to the query is the minimum number of coins that is necessary to obtain the value $b_j$ using some subset of coins (Polycarp can use only coins he has). If Polycarp can't obtain the value $b_j$, the answer to the $j$-th query is -1.

The queries are independent (the answer on the query doesn't affect Polycarp's coins).


-----Input-----

The first line of the input contains two integers $n$ and $q$ ($1 \le n, q \le 2 \cdot 10^5$) — the number of coins and the number of queries.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ — values of coins ($1 \le a_i \le 2 \cdot 10^9$). It is guaranteed that all $a_i$ are integer powers of $2$ (i.e. $a_i = 2^d$ for some non-negative integer number $d$).

The next $q$ lines contain one integer each. The $j$-th line contains one integer $b_j$ — the value of the $j$-th query ($1 \le b_j \le 10^9$).


-----Output-----

Print $q$ integers $ans_j$. The $j$-th integer must be equal to the answer on the $j$-th query. If Polycarp can't obtain the value $b_j$ the answer to the $j$-th query is -1.


-----Example-----
Input
5 4
2 4 8 2 4
8
5
14
10

Output
1
-1
3
2

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Greedy algorithms


Solutions:
from collections import Counter
(n, q) = map(int, input().split())
a = map(int, input().split())
b = [int(input()) for _ in range(q)]
counts = 32 * [0]
for (value, count) in Counter(a).items():
	counts[value.bit_length() - 1] = count
for bj in b:
	ans = 0
	for i in reversed(range(32)):
		count = min(bj >> i, counts[i])
		ans += count
		bj -= count << i
	if bj != 0:
		print(-1)
	else:
		print(ans)


DEGREE_ARRAY_SIZE = 32
VALUES = {2 ** i: i for i in range(DEGREE_ARRAY_SIZE)}

def convert(a):
	b = [0 for i in range(DEGREE_ARRAY_SIZE)]
	total = 0
	for val in a:
		b[VALUES[val]] += 1
		total += val
	start = 0
	for (i, cnt) in enumerate(reversed(b)):
		if cnt != 0:
			start = DEGREE_ARRAY_SIZE - i
			break
	return (b, total, start)

def calc(q, b):
	ans = 0
	val = 2 ** (len(b) - 1)
	for cnt in reversed(b):
		if q >= val:
			r = q % val
			d = q // val
			if cnt < d:
				r += (d - cnt) * val
				d = cnt
			q = r
			ans += d
			if q == 0:
				break
		val //= 2
	return ans if q == 0 else -1

def get_ints():
	return [int(n) for n in input().split()]

def get_floats():
	return [float(n) for n in input().split()]

def __starting_point():
	a = get_ints()
	assert len(a) == 2
	(n, q) = (a[0], a[1])
	a = get_ints()
	assert len(a) == n
	qj = [int(input()) for i in range(q)]
	assert len(qj) == q
	(b, total, start) = convert(a)
	b = b[:start]
	assert sum(b) == n
	DEGREE_ARRAY_SIZE = start
	for i in qj:
		if i < total:
			ans = calc(i, b)
		elif i == total:
			ans = n
		else:
			ans = -1
		print(ans)
__starting_point()


from collections import *
import sys
input = sys.stdin.readline
(n, q) = map(int, input().split())
a = list(map(int, input().split()))
f = Counter(a)
d = []
for i in f.keys():
	d.append([i, f[i]])
d.sort(reverse=True)
l1 = len(d)
for i in range(q):
	x = int(input())
	s = 0
	l = 0
	while x > 0 and l < len(d):
		q = x // d[l][0]
		q = min(d[l][1], q)
		if q != 0:
			s += q
			x -= q * d[l][0]
		l += 1
	if x == 0:
		print(s)
	else:
		print(-1)


DEGREE_ARRAY_SIZE = 32
b = [0 for i in range(DEGREE_ARRAY_SIZE)]

def convert(a):
	from collections import Counter
	for (val, cnt) in list(Counter(a).items()):
		b[val.bit_length() - 1] += cnt
	start = 0
	for (i, cnt) in enumerate(reversed(b)):
		if cnt != 0:
			start = DEGREE_ARRAY_SIZE - i
			break
	return (b, start)

def calc(q):
	ans = 0
	val_power = len(b) - 1
	for cnt in reversed(b):
		c = min(cnt, q >> val_power)
		q -= c * (1 << val_power)
		ans += c
		val_power -= 1
	return ans if q == 0 else -1

def get_ints():
	return [int(n) for n in input().split()]

def get_floats():
	return [float(n) for n in input().split()]

def __starting_point():
	a = get_ints()
	assert len(a) == 2
	(n, q) = (a[0], a[1])
	a = get_ints()
	assert len(a) == n
	(b, start) = convert(a)
	b = b[:start]
	DEGREE_ARRAY_SIZE = start
	q = [int(input()) for _ in range(q)]
	for i in q:
		ans = calc(i)
		print(ans)
__starting_point()


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
li = [0] * 32
for i in a:
	li[i.bit_length() - 1] += 1
queries = [int(input()) for _ in range(q)]
for k in queries:
	ans = 0
	for i in range(31, -1, -1):
		mini = min(k >> i, li[i])
		ans += mini
		k -= mini << i
	ans = ans if k == 0 else -1
	print(ans)


DEGREE_ARRAY_SIZE = 32
VALUES = {2 ** i: i for i in range(DEGREE_ARRAY_SIZE)}

def convert(a):
	from collections import Counter
	b = [0 for i in range(DEGREE_ARRAY_SIZE)]
	total = 0
	for (val, cnt) in list(Counter(a).items()):
		b[VALUES[val]] += cnt
		total += cnt * val
	start = 0
	for (i, cnt) in enumerate(reversed(b)):
		if cnt != 0:
			start = DEGREE_ARRAY_SIZE - i
			break
	return (b, total, start)

def calc(q, b):
	ans = 0
	val = 2 ** (len(b) - 1)
	for cnt in reversed(b):
		if q >= val:
			c = min(cnt, q // val)
			q -= c * val
			ans += c
			if q == 0:
				break
		val //= 2
	return ans if q == 0 else -1

def get_ints():
	return [int(n) for n in input().split()]

def get_floats():
	return [float(n) for n in input().split()]

def __starting_point():
	a = get_ints()
	assert len(a) == 2
	(n, q) = (a[0], a[1])
	a = get_ints()
	assert len(a) == n
	qj = [int(input()) for i in range(q)]
	assert len(qj) == q
	(b, total, start) = convert(a)
	b = b[:start]
	assert sum(b) == n
	DEGREE_ARRAY_SIZE = start
	for i in qj:
		if i < total:
			ans = calc(i, b)
		elif i == total:
			ans = n
		else:
			ans = -1
		print(ans)
__starting_point()


def convert(a):
	b = list()
	toAdd = a[0]
	cnt = 1
	for item in a[1:]:
		if item == toAdd:
			cnt += 1
		else:
			b.append((toAdd, cnt))
			toAdd = item
			cnt = 1
	b.append((toAdd, cnt))
	return b

def calc(q, b):
	ans = 0
	for item in b:
		(val, cnt) = item
		if q >= val:
			r = q % val
			d = q // val
			if cnt < d:
				r += (d - cnt) * val
				d = cnt
			q = r
			ans += d
			if q == 0:
				break
	return ans if q == 0 else -1

def get_ints():
	return [int(n) for n in input().split()]

def get_floats():
	return [float(n) for n in input().split()]
a = get_ints()
assert len(a) == 2
(n, q) = (a[0], a[1])
a = get_ints()
assert len(a) == n
qj = [int(input()) for i in range(q)]
assert len(qj) == q
a.sort()
a.reverse()
b = convert(a)
for i in qj:
	ans = calc(i, b)
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def find(m):
	p = 1
	while p <= m:
		p *= 2
	return p // 2
d = dict()
for i in range(32):
	d.update({2 ** i: 0})
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
for i in range(n):
	d[l[i]] += 1
for i in range(k):
	q = int(input())
	e = find(q)
	ans = 0
	f = 0
	while q > 0:
		t = q // e
		t = min(t, d[e])
		q -= t * e
		ans += t
		e //= 2
		if e == 0 and q > 0:
			f = 1
			break
	if f == 1:
		print(-1)
	else:
		print(ans)


from collections import Counter
getListInput = lambda : list(map(int, input().split()))
(NC, NQ) = getListInput()
CS = getListInput()
COUNTER = Counter(CS)
POWERS = [COUNTER[2 ** i] if 2 ** i in COUNTER else 0 for i in range(30)]
ANSWER = []
for _ in range(NQ):
	QT = int(input())
	MIN = 0
	for p in reversed(range(30)):
		coins = min(QT // 2 ** p, POWERS[p])
		MIN += coins
		QT -= coins * 2 ** p
	ANSWER.append(MIN if QT == 0 else -1)
print(' '.join(map(str, ANSWER)))


import sys
input = sys.stdin.buffer.readline
(n, q) = map(int, input().split())
arr = list(map(int, input().split()))
store = [0 for i in range(31)]
d = {}
for i in range(31):
	d[pow(2, i)] = i
for i in range(n):
	store[d[arr[i]]] += 1
for i in range(q):
	rt = int(input())
	st = bin(rt).replace('0b', '')
	st = st[::-1]
	count = 0
	manage = [0 for i in range(31)]
	for i in st:
		if i == str(1):
			manage[count] = 1
		count += 1
	total = 0
	for i in range(30, -1, -1):
		if manage[i] > 0 and i > 0:
			total += min(manage[i], store[i])
			manage[i] = max(0, manage[i] - store[i])
			manage[i - 1] += 2 * manage[i]
			manage[i] = 0
	if manage[0] > store[0]:
		print(-1)
		continue
	print(total + manage[0])


import collections
(n, q) = map(int, input().split())
s = [int(i) for i in input().split()]
a = [int(input()) for _ in range(q)]
dic = {}
for i in range(32):
	dic[i] = 0
for i in s:
	dic[i.bit_length() - 1] += 1
for s in a:
	ans = 0
	for i in range(31, -1, -1):
		count = min(s >> i, dic[i])
		ans += count
		s -= count << i
	print(ans if s == 0 else -1)


from sys import stdin
input = stdin.readline
(n, q) = map(int, input().split())
a = list(map(int, input().split()))
cnt = [0] * 31
for i in range(n):
	x = a[i]
	c = 0
	while x % 2 == 0:
		x //= 2
		c += 1
	cnt[c] += 1
f = [0] * 31
f[0] = 1
for i in range(1, 31):
	f[i] = f[i - 1] * 2
for _ in range(q):
	b = int(input())
	ans = 0
	for j in range(31)[::-1]:
		cur = min(b // f[j], cnt[j])
		b -= cur * f[j]
		ans += cur
	if b > 0:
		print(-1)
	else:
		print(ans)


from collections import Counter as C
from operator import itemgetter
from math import ceil, sqrt, gcd
from collections import defaultdict as dd
d = dd(lambda : 0)
from sys import stdin
input = stdin.readline

def mp():
	return map(int, input().split())

def it():
	return int(input())
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
c = C(l)
d = sorted(list(set(l)))
d.reverse()
for i in range(k):
	q = it()
	if d[-1] != 1 and q % 2 != 0:
		print(-1)
	else:
		count = 0
		for i in d:
			if q >= i:
				m = min(q // i, c[i])
				q -= m * i
				count += m
		if q:
			print(-1)
		else:
			print(count)


from sys import stdin, stdout
get_string = lambda : stdin.readline().strip('\n')
get_intmap = lambda : map(int, get_string().split(' '))

def ncr_generator(n, r):
	ncrr = 1
	while True:
		yield ncrr
		n += 1
		ncrr = ncrr * n // (n - r)
from collections import Counter

def testcase():
	(n, q) = get_intmap()
	a = tuple(get_intmap())
	cnt = Counter(a)
	keys = sorted(cnt.keys(), reverse=True)
	blist = [int(get_string()) for i in range(q)]
	ans = ['-1'] * q
	for ind in range(q):
		(b, tmp) = (blist[ind], 0)
		for key in keys:
			(q, r) = divmod(b, key)
			m = min(q, cnt[key])
			tmp += m
			b -= m * key
			if b == 0:
				ans[ind] = str(tmp)
				break
	print('\n'.join(ans))
testcase()


import io
import os
from collections import defaultdict
from sys import stdin
input = stdin.readline

def main():
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	d = defaultdict(int)
	for val in a:
		d[val] += 1
	coins = [(val, cnt) for (val, cnt) in d.items()]
	coins.sort(reverse=True)
	for _ in range(q):
		left = int(input())
		ans = 0
		for (val, cnt) in coins:
			take = min(cnt, left // val)
			ans += take
			left -= take * val
		print(str(ans) if left == 0 else str(-1))
main()


import sys
input = sys.stdin.buffer.readline
(n, q) = map(int, input().split())
arr = [int(x) for x in input().split()]
ques = []
for i in range(q):
	ques.append(int(input()))
dp = [0] * 31
for i in arr:
	s = bin(i)[2:]
	dp[len(s) - 1] = dp[len(s) - 1] + 1
for q in ques:
	l = list(bin(q)[2:])
	l = l[::-1]
	i = len(l) - 1
	cnt = 0
	ans = 0
	while i >= 0:
		if l[i] == '1':
			cnt = cnt + 1
		if dp[i] >= cnt:
			ans = ans + cnt
			cnt = 0
		else:
			ans = ans + dp[i]
			cnt = cnt - dp[i]
		cnt = 2 * cnt
		i = i - 1
	if cnt == 0:
		print(ans)
	else:
		print(-1)


import sys
input = lambda : sys.stdin.readline().rstrip()
(n, q) = map(int, input().split())
l = (2 * 10 ** 9).bit_length() + 2
a = [0] * l
for i in map(int, input().split()):
	cnt = 0
	while i > 1:
		i //= 2
		cnt += 1
	a[cnt] += 1
for _ in range(q):
	b = int(input())
	cnt = 0
	for i in range(l - 1, -1, -1):
		tmp = min(b // 2 ** i, a[i])
		cnt += tmp
		b -= 2 ** i * tmp
	if b > 0:
		print(-1)
	else:
		print(cnt)


from math import *
from sys import *
(n, q) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
powers = [1]
for i in range(1, 32):
	powers.append(2 * powers[-1])
arr = [0] * 32
for i in range(n):
	arr[int(log2(a[i]))] += 1
for _ in range(q):
	x = int(stdin.readline())
	ver = True
	ans = 0
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] != 0 and powers[i] <= x:
			cnt = min(x // powers[i], arr[i])
			x -= cnt * powers[i]
			ans += cnt
			if x == 0:
				break
	if x == 0:
		stdout.write(str(ans) + '\n')
	else:
		stdout.write('-1' + '\n')


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	(n, m) = mp()
	ans = []
	l = li()
	d = Counter(l)
	for i in range(m):
		x = inp()
		copy_d = dict(d)
		cur = 1
		while cur << 1 <= x:
			cur <<= 1
		now = 0
		while cur > 0:
			have = copy_d.get(cur, 0)
			can_fit = x // cur
			mi = min(have, can_fit)
			x -= mi * cur
			now += mi
			cur >>= 1
		if x == 0:
			ans.append(now)
		else:
			ans.append(-1)
	print(*ans, sep='\n')
for _ in range(1):
	solve()


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	d = collections.Counter(a)
	keys = sorted(d.keys(), reverse=True)
	for i in range(q):
		ans = 0
		b = int(input())
		for k in keys:
			cnt = b // k
			ans += min(cnt, d[k])
			b -= min(cnt, d[k]) * k
		if b > 0:
			print(-1)
		else:
			print(ans)
main()


import sys
input = lambda : sys.stdin.readline().rstrip()
(n, q) = map(int, input().split())
a = list(map(int, input().split()))
from collections import Counter
d = Counter(a)
sa = list(set(a))
sa.sort(reverse=1)
for _ in range(q):
	x = int(input())
	ans = 0
	for i in sa:
		if x >= i:
			m = min(x // i, d[i])
			x -= m * i
			ans += m
	if x:
		print(-1)
	else:
		print(ans)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import math

def function(z):
	x = int(math.log(z, 2))
	for i in range(x, -1, -1):
		if lis[i] > 0:
			a = power[i]
			b = z // a
			c = min(lis[i], b)
			lis[i] -= c
			z -= a * c
			arr[0] += c
			if z == 0:
				return True
	return False
(n, q) = list(map(int, input().split()))
arr = list(map(int, input().split()))
power = []
for i in range(32):
	power.append(2 ** i)
coins = [0] * 32
for i in range(n):
	temp = int(math.log(arr[i], 2))
	coins[temp] += 1
for i in range(q):
	lis = []
	for j in range(32):
		lis.append(coins[j])
	b = int(input())
	a = bin(b)[2:]
	l = len(a)
	num = []
	p = 0
	for j in range(l):
		if a[j] == '1':
			num.append(l - j - 1)
			p += 1
	arr = [0]
	s = 0
	for j in range(p):
		if function(power[num[j]]):
			continue
		else:
			s += 1
			break
	if s == 1:
		print(-1)
	else:
		print(arr[0])


from collections import defaultdict
import sys
input = sys.stdin.readline
(n, q) = map(int, input().split())
a = list(map(int, input().split()))
cnt = defaultdict(lambda : 0)
for i in a:
	cnt[i] += 1
pow2 = [1]
for _ in range(35):
	pow2.append(2 * pow2[-1])
for _ in range(q):
	x = [0] * 35
	b = int(input())
	ans = 0
	f = 1
	for i in range(34, 0, -1):
		p2 = pow2[i - 1]
		if not x[i] and (not b & p2):
			continue
		if b & p2:
			x[i] += 1
		ans += min(x[i], cnt[p2])
		if x[i] <= cnt[p2]:
			x[i] = 0
		else:
			c = x[i] - cnt[p2]
			x[i - 1] += 2 * c
	if x[0]:
		ans = -1
	print(ans)


import sys
from math import log
input = sys.stdin.readline
(n, q) = map(int, input().split())
coins = list(map(int, input().split()))
freq = [0 for i in range(32)]
for coin in coins:
	freq[int(log(coin, 2))] += 1
for j in range(q):
	b = int(input())
	c = 0
	for i in range(31, -1, -1):
		k = b // 2 ** i
		b -= min(k, freq[i]) * 2 ** i
		c += min(k, freq[i])
	if b:
		print(-1)
	else:
		print(c)


from typing import List
from collections import defaultdict
from sys import stdin, stdout

def binarySearch(arr: List, low: int, high: int, val: int):
	ans = 0
	while low <= high:
		mid = (low + high) // 2
		if arr[mid] > val:
			high = mid - 1
		elif arr[mid] == val:
			return mid
		else:
			ans = mid
			low = mid + 1
	return ans
(N, Q) = list(map(int, stdin.readline().split()))
coins = sorted(list(map(int, stdin.readline().split())))
freq = defaultdict(int)
for word in coins:
	freq[word] += 1
coins = sorted(list(freq.keys()))
for _ in range(Q):
	num = int(stdin.readline())
	index = binarySearch(coins, 0, len(coins) - 1, num)
	ans = 0
	while index >= 0 and num > 0:
		used = num // coins[index]
		if used >= freq[coins[index]]:
			used = freq[coins[index]]
		num -= coins[index] * used
		ans += used
		index -= 1
	if num == 0:
		stdout.write(str(ans))
	else:
		stdout.write('-1')
	stdout.write('\n')


from collections import Counter
rd = lambda : map(int, input().split(' '))
(n, q) = rd()
a = sorted(Counter(rd()).items(), reverse=True)
aa = []
for _ in range(q):
	b = int(input())
	ans = 0
	for (x, cnt) in a:
		to_del = cnt if x * cnt <= b else b // x
		ans += to_del
		b -= to_del * x
	aa.append(ans if b == 0 else -1)
print(' '.join(map(str, aa)))


import copy
import sys
input = sys.stdin.readline
BITS = 32
a = input().split(' ')
n = int(a[0])
q = int(a[1])
v = [int(i) for i in input().split(' ')]
cnt = [0 for i in range(BITS)]
for i in v:
	for j in range(BITS):
		if 1 << j == i:
			cnt[j] += 1
			break
res = []
for lgmoorz in range(q):
	cv = int(input())
	ok = True
	ans = 0
	csum = 0
	for j in range(BITS - 1, -1, -1):
		currpow = 1 << j
		canfit = (cv - csum) // currpow
		toadd = min(canfit, cnt[j])
		ans += toadd
		csum += toadd * currpow
	if csum == cv:
		res.append(ans)
	else:
		res.append(-1)
for j in res:
	sys.stdout.write(str(j) + '\n')


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
(n, q) = mapi()
a = list(mapi())
mp = defaultdict(int)
for i in a:
	j = 0
	while i >> j != 1:
		j += 1
	mp[j] += 1
st = max(mp.keys())
for i in range(q):
	m = int(input())
	res = 0
	for j in range(st, -1, -1):
		coins = min(m >> j, mp[j])
		m -= (1 << j) * coins
		res += coins
	if m:
		print(-1)
		continue
	print(res)


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
import math

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
no = 'NO'
yes = 'YES'

def solve():
	(n, q) = li()
	a = li()
	d = defaultdict(lambda : 0)
	for i in a:
		d[i] += 1
	k = list(d.keys())
	k.sort()
	k.reverse()
	for i in range(q):
		b = ii()
		cnt = 0
		f = 0
		for j in k:
			cnt += min(d[j], b // j)
			b = b - j * min(d[j], b // j)
		if b != 0:
			cnt = -1
		print(cnt)
t = 1
for _ in range(t):
	solve()


import atexit, io, sys, collections, math, heapq, fractions, copy, os, functools
import sys
import random
import collections
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, nq) = map(int, input().split())
ais = list(map(int, input().split()))
s = list(set(ais))
s.sort(key=lambda x: -x)
cc = collections.Counter(ais)

def f(s, cc, q):
	ans = 0
	for ai in s:
		if q >= ai:
			t = min(cc[ai], q // ai)
			q -= t * ai
			ans += t
		if q == 0:
			break
	return ans if q == 0 else -1
for _ in range(nq):
	q = int(input())
	print(f(s, cc, q))


import sys
input = sys.stdin.readline
out = sys.stdout

def cbits(x):
	i = 0
	while x:
		x >>= 1
		i += 1
	return i
bits = [0] * 31
(n, q) = map(int, input().split())
a = map(int, input().split())
for b in a:
	c = cbits(b) - 1
	bits[c] += 1
for i in range(q):
	ans = 0
	x = int(input())
	num = cbits(x)
	for j in range(num, -1, -1):
		p = 1 << j
		c = x // p
		t = min(bits[j], c) * p
		x -= t
		ans += min(bits[j], c)
		if x == 0:
			break
	if x == 0:
		out.write(str(ans) + '\n')
	else:
		out.write('-1' + '\n')


input = __import__('sys').stdin.readline
from math import log
from math import pow
(n, q) = map(int, input().split())
l = list(map(int, input().split()))
ans = [0] * 33
for i in range(n):
	x = int(log(l[i], 2))
	ans[x] += 1
for _ in range(q):
	y = int(input())
	out = 0
	for i in range(30, -1, -1):
		z = 0
		if y > 0:
			if y >> i:
				z = min(y >> i, ans[i])
			out += z
			y = y - int(pow(2, i)) * z
		else:
			break
	if y > 0:
		out = -1
	print(out)


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def MSB(n):
	ndx = 0
	while n > 1:
		n = n >> 1
		ndx += 1
	return ndx

def main():
	(n, q) = map(int, input().split())
	bits = [0] * 32
	arr = list(map(int, input().split()))
	for v in arr:
		bits[MSB(v)] += 1
	for i in range(q):
		v = int(input())
		cnt = 0
		for p in range(31, -1, -1):
			if bits[p] > 0:
				if 1 << p <= v:
					needed = v // (1 << p)
					take = min(needed, bits[p])
					cnt += take
					v -= take * (1 << p)
		if v != 0:
			print(-1)
		else:
			print(cnt)
main()


(n, q) = map(int, input().split())
ar = list(map(int, input().split()))
mArr = {}
for i in ar:
	if i in mArr:
		mArr[i] += 1
	else:
		mArr[i] = 1
ans = []
for _ in range(q):
	q = int(input())
	s = 0
	i = 1 << 30
	while i > 0:
		if i in mArr:
			n = min(mArr[i], q // i)
		else:
			n = 0
		s += n
		q -= n * i
		i //= 2
	ans.append('-1' if q > 0 else str(s))
print(' '.join(ans))


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
(N, Q) = MAP()
A = LIST()
C = sorted(Counter(A).items(), reverse=1)
out = []
for _ in range(Q):
	q = INT()
	ans = 0
	for (k, v) in C:
		cnt = min(q // k, v)
		q -= cnt * k
		ans += cnt
	if q > 0:
		out.append(str(-1))
	else:
		out.append(str(ans))
print('\n'.join(out))


from sys import stdin
from collections import Counter
(n, k) = map(int, input().split())
list1 = list(map(int, input().split()))
list1.sort(reverse=True)
list2 = []
for i in range(n):
	if list2:
		if list1[i] == list2[-1][0]:
			list2[-1][1] += 1
		else:
			list2.append([list1[i], 1])
	else:
		list2.append([list1[i], 1])
l = len(list2)
for _ in range(k):
	ele = int(stdin.readline())
	c = 0
	for i in range(l):
		x = list2[i][0]
		y = list2[i][1]
		if ele >= x:
			s = ele // x
			cc = min(s, y)
			c += cc
			ele -= x * cc
		if not ele:
			break
	if ele == 0:
		print(c)
	else:
		print(-1)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
from collections import Counter
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
(n, q) = iia()
d = Counter(iia())
for i in range(q):
	cur = ii1()
	count = 0
	for i in sorted(d, reverse=True):
		if cur >= i:
			temp = min(cur // i, d[i])
			cur -= temp * i
			count += temp
		if cur == 0:
			break
	if cur:
		print(-1)
	else:
		print(count)


import sys
input = sys.stdin.readline
from collections import defaultdict
(n, q) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = defaultdict(int)
for i in range(n):
	b[a[i]] += 1
c = []
for i in b:
	c.append([i, b[i]])
c.sort(reverse=True)
t = len(c)
for i in range(q):
	b = int(input())
	d = 0
	for j in range(t):
		d += min(b // c[j][0], c[j][1])
		b = b - c[j][0] * min(b // c[j][0], c[j][1])
	if b == 0:
		print(d)
	else:
		print(-1)


(n, Q) = map(int, input().split())
A = list(map(int, input().split()))
from collections import Counter
C = Counter(A)
C = list(C.items())
C.sort(reverse=True)
ANS = []
for i in range(Q):
	b = int(input())
	ans = 0
	for (k, v) in C:
		(q, r) = divmod(b, k)
		if q <= v:
			b = r
			ans += q
		else:
			b -= k * v
			ans += v
	if b == 0:
		ANS.append(ans)
	else:
		ANS.append(-1)
print(*ANS, sep='\n')


import collections
(n, q) = map(int, input().split())
a = list(map(int, input().split()))
li = [0] * 32
for (key, val) in collections.Counter(a).items():
	li[key.bit_length() - 1] = val
queries = [int(input()) for _ in range(q)]
for k in queries:
	ans = 0
	for i in range(31, -1, -1):
		mini = min(k >> i, li[i])
		ans += mini
		k -= mini << i
	ans = ans if k == 0 else -1
	print(ans)


def main():
	d = {}
	nums = [None] * 31
	for i in range(31):
		nums[i] = 2 ** i
		d[nums[i]] = 0
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		d[a[i]] += 1
	for i in range(31):
		if d[nums[i]] == 0:
			del d[nums[i]]
	keys = sorted(list(d.keys()))[::-1]
	leng = len(keys)
	ans = [0] * q
	for i in range(q):
		val = int(input())
		for j in range(leng):
			if keys[j] <= val:
				coin = min(d[keys[j]], val // keys[j])
				ans[i] += coin
				val -= keys[j] * coin
				if val == 0:
					break
		else:
			ans[i] = -1
	print('\n'.join(list(map(str, ans))))
main()


import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def main():
	(n, q) = rm()
	a = rl()
	b = []
	for i in range(q):
		b.append(r())
	coins = defaultdict(int)
	for i in a:
		coins[i] += 1
	for i in b:
		ans = 0
		if coins[i] > 0:
			print(1)
			continue
		for j in range(30, -1, -1):
			temp = min(i // 2 ** j, coins[2 ** j])
			i -= temp * 2 ** j
			ans += temp
			if i <= 0:
				break
		if i > 0:
			print(-1)
		else:
			print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
main()


import sys
input = sys.stdin.readline
from collections import Counter
(n, q) = map(int, input().split())
a = list(map(int, input().split()))
cnt = Counter(a)
k = list(cnt.keys())
k.sort(reverse=True)
for _ in range(q):
	b = int(input())
	ans = 0
	for ki in k:
		c = min(b // ki, cnt[ki])
		ans += c
		b -= c * ki
	if b > 0:
		print(-1)
	else:
		print(ans)


import sys
input = sys.stdin.readline
out = sys.stdout
(n, q) = map(int, input().split())
d = {}
for i in input().split():
	t = d.get(int(i), 0) + 1
	d[int(i)] = t
l = sorted(d.keys(), reverse=True)
for _ in range(q):
	b = int(input())
	s = 0
	for k in l:
		cur = min(int(b / k), d[k])
		s += cur
		b -= k * cur
	if b != 0:
		out.write('-1' + '\n')
	else:
		out.write(str(s) + '\n')


from sys import stdin

def main():
	input()
	(cc, nc, c, d) = ([0] * 31, [0] * 31, 1, {})
	for i in range(31):
		(d[str(c)], cc[i], c) = (i, c, c * 2)
	for i in map(d.get, input().split()):
		nc[i] += 1
	ncc = tuple(((n, c) for (n, c) in zip(nc, cc) if n))[::-1]
	(l, cache) = (stdin.read().splitlines(), {})
	for (i, s) in enumerate(l):
		if s in cache:
			l[i] = cache[s]
		else:
			(x, r) = (int(s), 0)
			for (n, c) in ncc:
				m = x // c
				if m > n:
					m = n
				x -= m * c
				r += m
				if not x:
					cache[s] = l[i] = str(r)
					break
			else:
				cache[s] = l[i] = '-1'
	print('\n'.join(l))
main()


import sys
from collections import defaultdict

def solve(io):
	N = io.readInt()
	Q = io.readInt()
	A = io.readIntArray(N)
	B = io.readIntArray(Q)
	freq = defaultdict(lambda : 0)
	for a in A:
		freq[a] += 1
	for b in B:
		cnt = 0
		p = 1 << 30
		while b > 0 and p > 0:
			want = b // p
			have = min(want, freq[p])
			b -= have * p
			cnt += have
			p = p >> 1
		if b == 0:
			io.println(cnt)
		else:
			io.println(-1)

class IO:
	input = None
	output = None
	raw = ''
	buf = []
	pos = 0

	def __init__(self, inputStream, outputStream):
		self.input = inputStream
		self.output = outputStream

	def readToBuffer(self):
		self.raw = self.input.readline().rstrip('\n')
		self.buf = self.raw.split()
		self.pos = 0

	def readString(self):
		while self.pos == len(self.buf):
			self.readToBuffer()
		ans = self.buf[self.pos]
		self.pos += 1
		return ans

	def readInt(self):
		return int(self.readString())

	def readFloat(self):
		return float(self.readString())

	def readStringArray(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.readString())
		return arr

	def readIntArray(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.readInt())
		return arr

	def readFloatArray(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.readFloat())
		return arr

	def readLine(self):
		while self.pos == len(self.buf):
			self.readToBuffer()
		if self.pos > 0:
			raise ValueError('Cannot call readline in the middle of a line.')
		return self.raw

	def print(self, s):
		self.output.write(str(s))

	def println(self, s):
		self.print(s)
		self.print('\n')

	def printlnArray(self, arr, sep=' '):
		self.println(sep.join((str(x) for x in arr)))

	def flushOutput(self):
		self.output.flush()
pythonIO = IO(sys.stdin, sys.stdout)
solve(pythonIO)
pythonIO.flushOutput()


from collections import Counter
getListInput = lambda : list(map(int, input().split()))
(NC, NQ) = getListInput()
CS = getListInput()
COUNTER = sorted(Counter(CS).items(), reverse=True)
ANSWER = []
for _ in range(NQ):
	QT = int(input())
	MIN = 0
	for (k, v) in COUNTER:
		coins = min(QT // k, v)
		MIN += coins
		QT -= coins * k
	ANSWER.append(MIN if QT == 0 else -1)
print(' '.join(map(str, ANSWER)))


input = __import__('sys').stdin.readline
from math import log
(n, q) = map(int, input().split())
lis = list(map(int, input().split()))
has1 = [0] * 33
for i in lis:
	a = int(log(i, 2))
	has1[a] += 1
c = 1
for _ in range(q):
	no = int(input())
	c = 1
	flag = 1
	ans = 0
	has = has1[:]
	for i in range(33):
		if c & no:
			if has[i] > 0:
				has[i] -= 1
				ans += 1
			else:
				k = 0
				c1 = 2
				for j in range(i - 1, -1, -1):
					k += has[j] / c1
					c1 *= 2
				if k < 1:
					flag = False
					break
				k = 0
				c1 = 2
				for j in range(i - 1, -1, -1):
					req = 1 - k
					if req >= has[j] / c1:
						ans += has[j]
						k += has[j] / c1
						has[j] = 0
					else:
						ans += req * c1
						has[j] = (has[j] / c1 - req) * c1
						break
					c1 *= 2
		c *= 2
	if flag:
		print(int(ans))
	else:
		print(-1)


import collections
(n, q) = map(int, input().split())
l = list(map(int, input().split()))
a = [int(input()) for _ in range(q)]
count = [0] * 31
for (key, val) in collections.Counter(l).items():
	count[key.bit_length() - 1] = val
for x in a:
	ans = 0
	for i in range(30, -1, -1):
		val = min(x >> i, count[i])
		ans += val
		x -= (1 << i) * val
	print(ans if x == 0 else -1)


def main():
	(n, q) = map(int, input().split())
	l = list(map(int, input().split()))
	from collections import defaultdict
	hash = defaultdict(int)
	for i in l:
		hash[i] += 1
	rd = []
	for i in range(30, -1, -1):
		rd.append(2 << i)
	final = []
	l = sorted(set(l))
	l.reverse()
	for i in range(q):
		z1 = int(input())
		ans = 0
		for i in l:
			d = min(hash[i], z1 // i)
			z1 -= d * i
			ans += d
		if z1 == 0:
			final.append(ans)
		else:
			final.append(-1)
	print(*final)
main()


from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))

def fast():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in fast().split()]
(z, zz) = (fast, lambda : map(int, z().split()))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer, end='\n'):
	stdout.write(str(answer) + end)
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
(n, k) = zzz()
arr = zzz()
lst = [0] * 31
for i in arr:
	lst[int(log2(i))] += 1
for i in range(k):
	x = int(z())
	ans = 0
	for j in range(30, -1, -1):
		cnt = min(x >> j, lst[j])
		ans += cnt
		x -= cnt << j
	if x == 0:
		output(ans)
	else:
		output(-1)


import sys
input = sys.stdin.readline
(n, q) = map(int, input().split())
l = list(map(int, input().split()))
d = {}
for i in l:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
for i in range(q):
	z = d.copy()
	x = int(input())
	v = bin(x)[2:]
	b = v[::-1]
	j = 0
	ans = 0
	f = 0
	while j < len(b):
		if b[j] == '1':
			k = j
			val = 2 ** j
			while k > -1 and val > 0:
				tval = 2 ** k
				if tval in z:
					e = z[tval]
					u = val // tval
					res = min(u, e)
					ans += res
					z[tval] -= res
					val -= tval * res
				k = k - 1
			if val > 0:
				f = 1
				break
		j += 1
	if f:
		sys.stdout.write('-1\n')
		continue
	w = str(ans)
	sys.stdout.write(w + '\n')


import os
import sys
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, q) = value()
a = Counter(array())
keys = sorted(a.keys(), reverse=True)
for _ in range(q):
	x = Int()
	ans = 0
	for k in keys:
		need = min(x // k, a[k])
		ans += need
		x -= need * k
	if x:
		ans = -1
	print(ans)