#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int t, n, m, i, j, k, sum = 0;
  cin >> n >> m;
  vector<long long int> a(m);
  map<long long int, long long int> mp;
  for (i = 0; i < m; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  vector<long long int> b;
  for (i = 0; i < 63; i++) {
    t = (1LL << i);
    if ((n >> i) & 1LL == 1LL) b.push_back((1LL << i));
  }
  reverse(b.begin(), b.end());
  long long int ans = 0;
  for (i = 0; i < m; i++) {
    if (b.empty()) break;
    if (a[i] > b.back()) {
      long long int x = a[i];
      mp[x]++;
      while (x != b.back()) {
        mp[x]--;
        x /= 2;
        mp[x] += 2;
        ans++;
      }
    } else {
      long long int x = a[i];
      mp[x]++;
      while (mp[x] > 1) {
        mp[x] -= 2;
        mp[x * 2]++;
        x *= 2;
      }
    }
    while (!b.empty() && mp[b.back()] > 0) {
      mp[b.back()]--;
      b.pop_back();
    }
  }
  if (b.empty())
    cout << ans << '\n';
  else
    cout << -1 << '\n';
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int q;
  cin >> q;
  while (q--) {
    solve();
  }
  return 0;
}
