#include <bits/stdc++.h>
using namespace std;
void sublimeOutput() {}
long long int n, m;
long long int a[100005];
void solve() {
  cin >> n >> m;
  for (long long int i = 0; i < m; i++) {
    cin >> a[i];
  };
  long long int p[64] = {0};
  long long int curr_sum = 0;
  for (long long int i = 0; i < m; i++) {
    p[int32_t(log2(a[i]))]++;
    curr_sum += a[i];
  }
  if (n > curr_sum) {
    cout << "-1"
         << "\n";
    return;
  }
  long long int i = 0;
  long long int ans = 0;
  while (i < 61) {
    if (((n >> i) & 1)) {
      if (p[i])
        p[i]--;
      else {
        while (i < 61 and !p[i]) {
          ans++;
          p[i]++;
          i++;
        }
        p[i]--;
        continue;
      }
    }
    p[i + 1] += p[i] / 2;
    i++;
  }
  cout << ans << endl;
}
int32_t main() {
  sublimeOutput();
  long long int t = 0;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
