#include <bits/stdc++.h>
using namespace std;
const int K = 62;
int cnt[K + 1];
void print() {
  for (int i = 0; i < K; i++)
    if (cnt[i])
      cout << "(" << i << " " << cnt[i] << ")"
           << ",  ";
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n;
    int m;
    cin >> n >> m;
    memset(cnt, 0, sizeof cnt);
    for (int i = 1; i <= m; i++) {
      long long x;
      cin >> x;
      cnt[__builtin_ctzll(x)]++;
    }
    int ans = 0;
    bool bad = false;
    for (int i = 0; i < K; i++) {
      if (n & (1LL << i)) {
        int id = -1;
        for (int j = i; j < K; j++)
          if (cnt[j]) {
            id = j;
            break;
          }
        if (id == -1) {
          bad = true;
          break;
        }
        for (int j = id; j > i; j--) {
          cnt[j]--;
          cnt[j - 1] += 2;
          ans++;
        }
        assert(cnt[i]);
        cnt[i]--;
      }
      cnt[i + 1] += cnt[i] / 2;
      cnt[i] = 0;
    }
    if (bad)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
}
