#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937 gen(228);
void solve() {
  ll n, m;
  cin >> n >> m;
  vector<int> have(100);
  for (int i = 0; i < m; i++) {
    ll v;
    cin >> v;
    int cnt = 0;
    while (v) {
      cnt++;
      v >>= 1;
    }
    cnt--;
    have[cnt]++;
  }
  int min_fit = 228;
  ((void)0);
  vector<int> need;
  int ans = 0;
  for (int i = 0; i < 62; i++) {
    if ((n & (1LL << i))) {
      ((void)0);
      if (have[i] == 0) {
        int from = -1;
        for (int j = i + 1; j < 62; j++) {
          if (have[j] > 0) {
            from = j;
            break;
          }
        }
        if (from == -1) {
          cout << "-1\n";
          return;
        }
        have[from]--;
        for (int j = i + 1; j < from; j++) {
          have[j]++;
        }
        have[i] += 2;
        ans += from - i;
      }
      have[i]--;
    }
    have[i + 1] += have[i] / 2;
  }
  cout << ans << "\n";
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
