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

Difficulty: introductory

Starter code:

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)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
http://codeforces.com/contest/1003/problem/D
"""

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:  #2**mid<val:
			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')
"""
/***

5 4
2 4 8 2 4
8
5
14
10
---
1
-1
3
2

5 5
2 4 8 2 1073741824
8
5
14
10
1073741824
---
1
-1
3
2
1

***/
"""

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)

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)

#!/usr/bin/env python3
# encoding: utf-8

from collections import Counter

n, q = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [int(input()) for _ in range(q)]

counts = 32 * [0]

for value, count in list(Counter(a).items()):
    counts[value.bit_length() - 1] = count

for bj in b:
    ans = 0

    for i in reversed(list(range(32))):
        count = min(bj >> i, counts[i])
        ans += count
        bj -= count << i

    if bj != 0:
        print(-1)
    else:
        print(ans)


#!/usr/bin/env python3
# encoding: utf-8



#----------
# Constants
#----------

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

#----------
# Functions
#----------
def convert(a):
    from collections import Counter
    #b = [ 0 for i in range(DEGREE_ARRAY_SIZE) ]
    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
        #if q == 0:
        #    break
        val_power -= 1

    return ans if q == 0 else -1


# Reads a string from stdin, splits it by space chars, converts each
# substring to int, adds it to a list and returns the list as a result.
def get_ints():
    return [ int(n) for n in input().split() ]


# Reads a string from stdin, splits it by space chars, converts each substring
# to floating point number, adds it to a list and returns the list as a result.
def get_floats():
    return [ float(n) for n in input().split() ]


#----------
# Execution start point
#----------

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)
#    print(str(b))
#    print(total)
    b = b[:start]
    DEGREE_ARRAY_SIZE = start
#    print(str(b))

    q = [int(input()) for _ in range(q)]
    for i in q:
        ans = calc(i)
        print(ans)

__starting_point()

#!/usr/bin/env python3
# encoding: utf-8



#----------
# Constants
#----------

DEGREE_ARRAY_SIZE = 32

#----------
# Functions
#----------
def convert(a):
    from collections import Counter
    b = [ 0 for i in range(DEGREE_ARRAY_SIZE) ]
    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, b):
    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
        #if q == 0:
        #    break
        val_power -= 1

    return ans if q == 0 else -1


# Reads a string from stdin, splits it by space chars, converts each
# substring to int, adds it to a list and returns the list as a result.
def get_ints():
    return [ int(n) for n in input().split() ]


# Reads a string from stdin, splits it by space chars, converts each substring
# to floating point number, adds it to a list and returns the list as a result.
def get_floats():
    return [ float(n) for n in input().split() ]


#----------
# Execution start point
#----------

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)
#    print(str(b))
#    print(total)
    b = b[:start]
    DEGREE_ARRAY_SIZE = start
#    print(str(b))

    q = [int(input()) for _ in range(q)]
    for i in q:
        ans = calc(i, b)
        print(ans)

__starting_point()

#!/usr/bin/env python3
# encoding: utf-8



#----------
# Constants
#----------

DEGREE_ARRAY_SIZE = 32

#----------
# Functions
#----------
def convert(a):
    from collections import Counter
    b = [ 0 for i in range(DEGREE_ARRAY_SIZE) ]
    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, b):
    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
        if q == 0:
            break
        val_power -= 1

    return ans if q == 0 else -1


# Reads a string from stdin, splits it by space chars, converts each
# substring to int, adds it to a list and returns the list as a result.
def get_ints():
    return [ int(n) for n in input().split() ]


# Reads a string from stdin, splits it by space chars, converts each substring
# to floating point number, adds it to a list and returns the list as a result.
def get_floats():
    return [ float(n) for n in input().split() ]


#----------
# Execution start point
#----------

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)
#    print(str(b))
#    print(total)
    b = b[:start]
    DEGREE_ARRAY_SIZE = start
#    print(str(b))

    q = [int(input()) for _ in range(q)]
    for i in q:
        ans = calc(i, b)
        print(ans)

__starting_point()

#!/usr/bin/env python3
# encoding: utf-8



#----------
# Constants
#----------

DEGREE_ARRAY_SIZE = 32

#----------
# Functions
#----------
def convert(a):
    from collections import Counter
    b = [ 0 for i in range(DEGREE_ARRAY_SIZE) ]
    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, b):
    ans = 0
    val = 2 ** (len(b) - 1)
    for cnt in reversed(b):
        c = min(cnt, q // val)
        q -= c * val
        ans += c
        if q == 0:
            break
        val //= 2

    return ans if q == 0 else -1


# Reads a string from stdin, splits it by space chars, converts each
# substring to int, adds it to a list and returns the list as a result.
def get_ints():
    return [ int(n) for n in input().split() ]


# Reads a string from stdin, splits it by space chars, converts each substring
# to floating point number, adds it to a list and returns the list as a result.
def get_floats():
    return [ float(n) for n in input().split() ]


#----------
# Execution start point
#----------

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, start = convert(a)
#    print(str(b))
#    print(total)
    b = b[:start]
    DEGREE_ARRAY_SIZE = start
#    print(str(b))

    for i in qj:
        ans = calc(i, b)
        print(ans)

__starting_point()

#!/usr/bin/env python3
# encoding: utf-8



#----------
# Constants
#----------

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

#----------
# Functions
#----------
def convert(a):
    from collections import Counter
    b = [ 0 for i in range(DEGREE_ARRAY_SIZE) ]
    for val, cnt in list(Counter(a).items()):
        b[VALUES[val]] += 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, b):
    ans = 0
    val = 2 ** (len(b) - 1)
    for cnt in reversed(b):
        c = min(cnt, q // val)
        q -= c * val
        ans += c
        if q == 0:
            break
        val //= 2

    return ans if q == 0 else -1


# Reads a string from stdin, splits it by space chars, converts each
# substring to int, adds it to a list and returns the list as a result.
def get_ints():
    return [ int(n) for n in input().split() ]


# Reads a string from stdin, splits it by space chars, converts each substring
# to floating point number, adds it to a list and returns the list as a result.
def get_floats():
    return [ float(n) for n in input().split() ]


#----------
# Execution start point
#----------

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, start = convert(a)
#    print(str(b))
#    print(total)
    b = b[:start]
    DEGREE_ARRAY_SIZE = start
#    print(str(b))

    for i in qj:
        ans = calc(i, b)
        print(ans)

__starting_point()

#!/usr/bin/env python3
# encoding: utf-8



#----------
# Constants
#----------

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

#----------
# Functions
#----------
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):
        c = min(cnt, q // val)
        q -= c * val
        ans += c
        if q == 0:
            break
        val //= 2

    return ans if q == 0 else -1


# Reads a string from stdin, splits it by space chars, converts each
# substring to int, adds it to a list and returns the list as a result.
def get_ints():
    return [ int(n) for n in input().split() ]


# Reads a string from stdin, splits it by space chars, converts each substring
# to floating point number, adds it to a list and returns the list as a result.
def get_floats():
    return [ float(n) for n in input().split() ]


#----------
# Execution start point
#----------

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()

#!/usr/bin/env python3
# encoding: utf-8



#----------
# Constants
#----------

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

#----------
# Functions
#----------
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


# Reads a string from stdin, splits it by space chars, converts each
# substring to int, adds it to a list and returns the list as a result.
def get_ints():
    return [ int(n) for n in input().split() ]


# Reads a string from stdin, splits it by space chars, converts each substring
# to floating point number, adds it to a list and returns the list as a result.
def get_floats():
    return [ float(n) for n in input().split() ]


#----------
# Execution start point
#----------

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()

#!/usr/bin/env python3
# encoding: utf-8



#----------
# Constants
#----------

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

#----------
# Functions
#----------
def convert(a):
    from collections import Counter
    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:
            c = min(cnt, q // val)
            q -= c * val
            ans += c
            if q == 0:
                break
        val //= 2

    return ans if q == 0 else -1


# Reads a string from stdin, splits it by space chars, converts each
# substring to int, adds it to a list and returns the list as a result.
def get_ints():
    return [ int(n) for n in input().split() ]


# Reads a string from stdin, splits it by space chars, converts each substring
# to floating point number, adds it to a list and returns the list as a result.
def get_floats():
    return [ float(n) for n in input().split() ]


#----------
# Execution start point
#----------

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()

#!/usr/bin/env python3
# encoding: utf-8



#----------
# Constants
#----------

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

#----------
# Functions
#----------
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 * cnt:
        #    q -= val * cnt
        #    ans += cnt
        #    if q == 0:
        #        break
        if q >= val:
        #    c = min(cnt, q // val)
        #    q -= c * val
        #    ans += c
            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


# Reads a string from stdin, splits it by space chars, converts each
# substring to int, adds it to a list and returns the list as a result.
def get_ints():
    return [ int(n) for n in input().split() ]


# Reads a string from stdin, splits it by space chars, converts each substring
# to floating point number, adds it to a list and returns the list as a result.
def get_floats():
    return [ float(n) for n in input().split() ]


#----------
# Execution start point
#----------

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()

#!/usr/bin/env python3
# encoding: utf-8



#----------
# Constants
#----------

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

#----------
# Functions
#----------
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 * cnt:
            q -= val * cnt
            ans += cnt
            if q == 0:
                break
        elif q >= val:
        #    c = min(cnt, q // val)
        #    q -= c * val
        #    ans += c
            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


# Reads a string from stdin, splits it by space chars, converts each
# substring to int, adds it to a list and returns the list as a result.
def get_ints():
    return [ int(n) for n in input().split() ]


# Reads a string from stdin, splits it by space chars, converts each substring
# to floating point number, adds it to a list and returns the list as a result.
def get_floats():
    return [ float(n) for n in input().split() ]


#----------
# Execution start point
#----------

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()

#!/usr/bin/env python3
# encoding: utf-8



#----------
# Constants
#----------



#----------
# Functions
#----------
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


# Reads a string from stdin, splits it by space chars, converts each
# substring to int, adds it to a list and returns the list as a result.
def get_ints():
    return [ int(n) for n in input().split() ]


# Reads a string from stdin, splits it by space chars, converts each substring
# to floating point number, adds it to a list and returns the list as a result.
def get_floats():
    return [ float(n) for n in input().split() ]


#----------
# Execution start point
#----------

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

    a.sort()
    a.reverse()
#    print(a)
    b = convert(a)
#    print(b)

    for i in qj:
        ans = calc(i, b)
        print(ans)

__starting_point()

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)

import collections
n, q = map(int,input().split())
s = [int(i) for i in input().split()]
a = [int(input()) for _ in range(q)]
dic = [0] * 32
for key, val in collections.Counter(s).items():
    dic[key.bit_length()-1] = val
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)

import collections
n, q = map(int,input().split())
s = [int(i) for i in input().split()]
a = [int(input()) for _ in range(q)]
'''dic = [0] * 32
for key, val in collections.Counter(s).items():
    dic[key.bit_length()-1] = val'''
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)

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():
	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()