#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 1;
const long long mod = 1e9 + 7;
template <typename T>
istream &operator>>(istream &is, vector<T> &A);
void solve() {
  long long n;
  cin >> n;
  int m;
  cin >> m;
  vector<long long> arr(m);
  cin >> arr;
  long long sum = accumulate(arr.begin(), arr.end(), 0LL);
  if (sum < n) {
    cout << "-1\n";
    return;
  }
  map<long long, long long> mp;
  for (auto &it : arr) {
    mp[(long long)log2(it)]++;
  };
  int ans = 0;
  for (long long i = 0; i < 63; i++) {
    if (mp.count(i)) {
      if ((1LL << i) & n) mp[i]--;
      while (mp[i] > 1) {
        mp[i + 1]++;
        mp[i] -= 2;
      }
      if (mp[i] == 0) mp.erase(i);
    } else if ((1LL << i) & n) {
      auto it = mp.lower_bound(i);
      ;
      ans += it->first - i;
      it->second--;
      long long x = it->first;
      while (x > i) {
        x--;
        mp[x]++;
      }
      if (it->second == 0) mp.erase(it);
    };
  }
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  cin >> t;
  for (int I = 1; I <= t; I++) {
    solve();
  }
  return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &A) {
  for (int i = 0; i < A.size(); i++) is >> A[i];
  return is;
}
