#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e9 + 7;
const long long int mod = 1e9 + 7;
void call_priyanshu() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
long long int mini(long long int a, long long int b) {
  if (a >= b) return b;
  return a;
}
long long int maxi(long long int a, long long int b) {
  if (a >= b) return a;
  return b;
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  vector<long long int> A(m);
  long long int sum = 0;
  vector<long long int> cnt(70, 0);
  for (long long int i = 0; i <= m - 1; i++) {
    cin >> A[i];
    sum += A[i];
    long long int num = A[i];
    long long int c = 0;
    while (num % 2 == 0) {
      num /= 2;
      c++;
    }
    cnt[c]++;
  }
  if (sum == n) cout << "0\n";
  if (sum < n) cout << "-1\n";
  if (sum <= n) return;
  vector<long long int> b(70, 0);
  for (long long int i = 60; i >= 0; i--) {
    if ((n >> i) & 1) {
      b[i]++;
    }
  }
  long long int ans = 0;
  for (long long int i = 0; i <= 60; i++) {
    if (b[i]) {
      if (cnt[i]) {
        cnt[i]--;
      } else {
        long long int idx = -1;
        for (long long int j = i + 1; j <= 60; j++) {
          if (cnt[j]) {
            idx = j;
            break;
          }
        }
        if (idx == -1) {
          cout << "-1\n";
          return;
        }
        cnt[idx]--;
        for (long long int j = i + 1; j <= idx - 1; j++) {
          cnt[j]++;
          ans++;
        }
        ans++;
      }
    }
    cnt[i + 1] += cnt[i] / 2;
  }
  cout << ans;
  cout << "\n";
}
int main() {
  call_priyanshu();
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
