#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m, sum = 0;
  cin >> n >> m;
  long long a[m];
  multiset<long long> s;
  for (long long i = 0; i < m; i++) {
    cin >> a[i];
    sum += a[i];
    long long x = 0;
    while (a[i] > 1) {
      x++;
      a[i] >>= 1;
    }
    s.insert(x);
  }
  if (sum < n) {
    cout << -1 << "\n";
    return;
  }
  long long ans = 0;
  for (long long i = 0; i < 62; i++) {
    if ((n >> i) & 1) {
      if (s.find(i) != s.end()) {
        s.erase(s.find(i));
      } else {
        long long x = *s.begin();
        s.erase(s.begin());
        ans++;
        for (long long j = x - 1; j > i; j--) {
          ans++;
          s.insert(j);
        }
      }
    }
    long long x = s.count(i);
    if (x & 1) s.erase(s.find(i));
    x /= 2;
    while (x--) {
      s.erase(s.find(i));
      s.erase(s.find(i));
      s.insert(i + 1);
    }
  }
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}
