#include <bits/stdc++.h>
using namespace std;
int get_power(int num) {
  int i = 0;
  while (num != 1) {
    num >>= 1;
    i++;
  }
  return i;
}
vector<int> get_power_vec(vector<int> nums) {
  vector<int> power(32, 0);
  vector<int>::iterator ite = nums.begin();
  while (ite != nums.end()) {
    power[get_power(*ite)]++;
    ite++;
  }
  return power;
}
int is_obtian(vector<int> nums, int num) {
  int nCount = 0;
  for (int i = (int)nums.size() - 1; i >= 1; i--) {
    if (nums[i] > 0 && num >= (1 << i)) {
      nCount++;
      nums[i]--;
      num -= 1 << i;
      i++;
    }
  }
  return num <= nums[0] ? nCount + num : -1;
}
int main() {
  int n, q;
  cin >> n >> q;
  vector<int> nums(n);
  vector<int> querys(q);
  vector<int> p(33);
  for (int i = 0; i < n; i++) cin >> nums[i];
  for (int i = 0; i < q; i++) cin >> querys[i];
  p = get_power_vec(nums);
  cout << ("p") << ":";
  for (auto var : p) cout << var << " ";
  cout << endl;
  vector<int>::iterator ite = querys.begin();
  while (ite != querys.end()) {
    cout << is_obtian(p, *ite) << endl;
    ite++;
  }
  return 0;
}
