#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const long long int N = 100005;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
    cin >> m >> n;
    long long int a[n];
    map<long long int, long long int> mp;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      mp[a[i]]++;
      sum += a[i];
    }
    if (sum < m) {
      cout << -1 << '\n';
    } else {
      set<long long int> St;
      for (i = 0; i < 62; i++) {
        if (m >> i & 1ll) {
          St.insert(1ll << i);
        }
      }
      cnt = 1;
      sum = 0;
      for (auto x : St) {
        while (cnt <= x) {
          sum += mp[cnt] * cnt;
          cnt *= 2;
        }
        if (sum >= x)
          sum -= x;
        else {
          long long int nxt = cnt;
          while (mp[nxt] == 0) {
            nxt *= 2;
          }
          mp[nxt]--;
          ans += log2(nxt / x);
          while (nxt > x) {
            nxt /= 2;
            mp[nxt]++;
          }
        }
      }
      cout << ans << '\n';
    }
  }
}
