#include <bits/stdc++.h>
using namespace std;
const int M = (int)1e5 + 5;
long long n;
int m, have[62];
inline void solve() {
  memset(have, 0, sizeof(have));
  cin >> n >> m;
  long long sum = 0;
  for (int i = 1; i <= m; i++) {
    int x;
    cin >> x;
    have[int(log2(x))]++;
    sum += x;
  }
  if (sum < n) {
    cout << -1 << endl;
    return;
  }
  int col = 0;
  int i = 0;
  while (i < 61) {
    if ((1LL << i) & n) {
      if (have[i] > 0)
        have[i]--;
      else {
        while (have[i] == 0 && i < 61) {
          i++;
          col++;
        }
        have[i]--;
        continue;
      }
    }
    have[i + 1] += have[i] / 2;
    i++;
  }
  cout << col << endl;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int tt = 1;
  cin >> tt;
  while (tt--) {
    solve();
  }
  return 0;
}
