#include <bits/stdc++.h>
using namespace std;
int q;
void solve() {
  long long n, m, ans = 0, x[100], y[100];
  memset(y, 0, sizeof y);
  cin >> n >> m;
  for (int i = 0; i < 63; i++) x[i] = bool((1LL << i) & n);
  for (int i = 1; i <= m; i++) {
    long long k;
    cin >> k;
    y[int(log2(k))]++;
  }
  for (int i = 0; i < 63; i++) {
    if (!x[i]) {
      y[i + 1] += y[i] / 2;
      continue;
    }
    if (y[i]) {
      y[i + 1] += (y[i] - 1) / 2;
      continue;
    }
    int c = i + 1;
    while (!y[c] && c < 63) c++;
    if (c == 63) {
      cout << "-1\n";
      return;
    }
    while (c > i) y[c]--, y[c - 1] += 2, ans++, c--;
  }
  cout << ans << "\n";
}
int main() {
  cin >> q;
  while (q--) solve();
}
