#include <bits/stdc++.h>
using namespace std;
long long t, n, m;
long long ar[100005];
signed main() {
  cin >> t;
  while (t--) {
    map<long long, long long> mp;
    long long ans = 0;
    cin >> n >> m;
    long long sum = 0;
    for (long long i = 0; i < m; i++) {
      cin >> ar[i];
      sum += ar[i];
    }
    if (sum < n) {
      cout << -1 << '\n';
      continue;
    }
    for (long long i = 0; i < m; i++) {
      long long cnt = 0;
      while (ar[i] > 1) {
        ar[i] /= 2;
        cnt++;
      }
      ar[i] = cnt;
      mp[ar[i]]++;
    }
    for (long long i = 0; i < 64; i++) {
      if (n & (1LL << i)) {
        if (!mp[i]) {
          for (long long j = i + 1; j < 64; j++) {
            if (mp[j]) {
              long long k = j;
              while (k > i) {
                mp[k]--;
                ans++;
                k--;
                mp[k] += 2;
              }
              break;
            }
          }
        }
        mp[i]--;
        mp[i + 1] += mp[i] / 2;
        mp[i] = 0;
      } else {
        mp[i + 1] += mp[i] / 2;
        mp[i] = 0;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
