#include <bits/stdc++.h>
using namespace std;
long long const inf = 1e9;
long long const mod = 1e9 + 7;
long double const eps = 1e-13;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> k >> n;
    long long a[n];
    long long cnt[60];
    memset(cnt, 0, sizeof(cnt));
    for (int i = (0); i < (n); i++) {
      cin >> a[i];
      int K = log2(a[i]);
      cnt[K]++;
    }
    vector<int> v;
    for (int i = (0); i < (60); i++) {
      if (k & (1LL << i)) v.push_back(i);
    }
    long long ans = 0;
    bool ok = true;
    for (auto u : v) {
      if (cnt[u] > 0) {
        cnt[u]--;
      } else {
        long long carry = 0;
        for (int i = (0); i < (u); i++) {
          carry = (carry + cnt[i]) / 2;
        }
        if (carry > 0) {
          long long del = 2;
          for (int i = u - 1; i >= 0; i--) {
            if (cnt[i] >= del) {
              cnt[i] -= del;
              break;
            } else {
              del -= cnt[i];
              cnt[i] = 0;
              del *= 2;
            }
          }
        } else {
          int p = -1;
          for (int i = (u + 1); i < (60); i++) {
            if (cnt[i] > 0) {
              p = i;
              break;
            }
          }
          if (p == -1) {
            ok = false;
            break;
          }
          for (int i = p; i > u; i--) {
            cnt[i]--;
            cnt[i - 1] += 2;
            ans++;
          }
          cnt[u]--;
        }
      }
    }
    if (!ok) {
      cout << -1 << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}
