#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const long long lim = (long long)3e16;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const long long oo = 1e18 + 5;
int t;
void solve() {
  long long n;
  int m;
  cin >> n >> m;
  long long sum = 0;
  vector<int> bits(100);
  for (int i = 0; i < m; ++i) {
    long long x;
    cin >> x;
    sum += x;
    int cnt = 0;
    while (x > 1) x /= 2, ++cnt;
    ++bits[cnt];
  }
  if (sum < n) {
    cout << -1 << '\n';
    return;
  }
  int ans = 0;
  for (int i = 0; i < 60; ++i) {
    if ((n >> i) & 1) {
      if (!bits[i]) {
        for (int j = i; j < 60; ++j) {
          if (bits[j]) {
            --bits[j];
            ans += j - i;
            break;
          }
          ++bits[j];
        }
        ++bits[i];
      }
      --bits[i];
    }
    bits[i + 1] += bits[i] / 2;
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
