#include <bits/stdc++.h>
using namespace std;
mt19937 gen;
void run() {
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    vector<int> cnt(100);
    long long sum = 0;
    for (int i = 0; i < m; i++) {
      int first;
      cin >> first;
      sum += first;
      for (int j = 0; j < 64; j++) {
        if (first >> j & 1) {
          cnt[j]++;
          break;
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < 64; i++) {
      if (n >> i & 1) {
        if (cnt[i]) {
          cnt[i]--;
          n -= (1LL << i);
        } else {
          while (!cnt[i]) {
            bool did = 0;
            for (int j = i + 1; j < 64; j++) {
              if (cnt[j]) {
                cnt[j]--;
                cnt[j - 1] += 2;
                did = 1;
                ans++;
                break;
              }
            }
            if (!did) break;
          }
          if (!cnt[i]) {
            ans = -1;
            break;
          }
          cnt[i]--;
          n -= (1LL << i);
        }
      }
      cnt[i + 1] += cnt[i] / 2;
    }
    cout << ans << '\n';
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  run();
}
