#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long num, n, ans = 0, sum = 0;
  cin >> num >> n;
  vector<long long> a(70);
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a[log2(x)]++;
    sum += x;
  }
  if (sum < num) {
    cout << -1 << endl;
    return;
  }
  for (long long i = 0; i < 64; i++) {
    if (num & (1LL << i)) {
      if (a[i] == 0) {
        long long j = i;
        for (j = i; j < 65; j++) {
          if (a[j]) break;
        }
        for (long long k = j; k > i; k--) {
          ans += 1;
          a[k] -= 1;
          a[k - 1] += 2;
        }
      }
      a[i] -= 1;
    }
    if (a[i]) {
      a[i + 1] += a[i] / 2;
      a[i] = 0;
    }
  }
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
