#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  unsigned long long t;
  cin >> t;
  while (t--) {
    unsigned long long n, m;
    cin >> n >> m;
    swap(n, m);
    vector<unsigned long long> A(n);
    unsigned long long sum = 0;
    vector<unsigned long long> cnt(60);
    for (unsigned long long i = 0; i < n; i++) {
      cin >> A[i];
      sum += A[i];
      unsigned long long cnt1 = 0;
      while (A[i] > 1) {
        A[i] = A[i] / 2;
        cnt1++;
      }
      cnt[cnt1]++;
    }
    if (sum < m) {
      cout << -1 << "\n";
    } else {
      vector<unsigned long long> powers;
      n = m;
      while (n > 0) {
        powers.push_back(n % 2);
        n = n / 2;
      }
      unsigned long long sum = 0;
      unsigned long long j = 0;
      unsigned long long ans = 0;
      for (unsigned long long i = 0; i < powers.size(); i++) {
        if (!powers[i]) {
          sum += (1 << i) * cnt[i];
          continue;
        }
        sum += (1 << i) * cnt[i];
        if (sum >= (1 << i)) {
          sum -= (1 << i);
        } else {
          unsigned long long l = 0;
          for (unsigned long long j = i + 1; j < 60; j++) {
            if (cnt[j] >= 1) {
              l = j;
              cnt[j]--;
              break;
            }
          }
          for (unsigned long long d = i; d < l; d++) {
            ans++;
            cnt[d]++;
          }
          sum += (1 << i);
        }
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
