#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  long long sz = 65;
  long long sum = 0;
  vector<long long> cnt(sz, 0);
  for (long long i = 0; i < m; i++) {
    long long x;
    cin >> x;
    sum += x;
    long long lg = 0;
    while (x > 1) {
      lg++;
      x /= 2;
    }
    cnt[lg]++;
  }
  if (sum < n) {
    cout << -1 << '\n';
    return;
  }
  long long lim = 0;
  long long ans = 0;
  for (long long b = 0; b <= 60; b++) {
    if (n & (1LL << b)) {
      if (cnt[b] > 0) {
        cnt[b]--;
      } else {
        long long id = -1;
        for (long long i = b; i < 64; i++) {
          if (cnt[i] > 0) {
            id = i;
            break;
          }
        }
        for (long long i = id; i - 1 >= b; i--) {
          cnt[i]--;
          cnt[i - 1] += 2;
          ans++;
        }
        b--;
        continue;
      }
    } else {
    }
    cnt[b + 1] += cnt[b] / 2;
    cnt[b] %= 2;
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
