#include <bits/stdc++.h>
using namespace std;
long long int arr[111111];
map<long long int, int> mm;
int main(void) {
  int t;
  scanf("%d", &t);
  long long int ll = 1;
  for (int e = 0; e < 33; e++) {
    mm[ll] = e;
    ll *= 2;
  }
  while (t--) {
    long long int n;
    int m;
    scanf("%lld%d", &n, &m);
    vector<long long int> v;
    for (int e = 0; e < m; e++) scanf("%lld", &arr[e]);
    sort(arr, arr + m);
    long long int nr = 1;
    while (n != 0) {
      if (n % 2) v.push_back(nr);
      nr *= 2;
      n /= 2;
    }
    long long int ans = 0, ll = 0, num = 0, err = 0;
    priority_queue<pair<long long int, long long int> > pq;
    for (int e = 0; e < v.size(); e++) {
      for (int r = ll; r < m; r++) {
        if (arr[r] > v[e])
          break;
        else {
          num += arr[r];
          pq.push(make_pair(arr[r], 1));
          ll = r + 1;
        }
      }
      if (num < v[e]) {
        if (ll == m) {
          err++;
          break;
        }
        long long int vn = arr[ll];
        long long int nn = (arr[ll] / v[e]);
        ans += mm[nn];
        pq.push(make_pair(v[e], nn));
        num += arr[ll];
        ll++;
      }
      long long int now = v[e];
      while (!pq.empty()) {
        if (now == 0) break;
        long long int val = pq.top().first, dist = pq.top().second;
        long long int rr = (now / val);
        long long int kk = min(rr, dist);
        now -= kk * val;
        dist -= kk;
        pq.pop();
        if (dist) pq.push(make_pair(val, dist));
      }
      if (now) err++;
      num -= v[e];
    }
    if (err)
      printf("-1\n");
    else
      printf("%d\n", ans);
  }
  return 0;
}
