#include <bits/stdc++.h>
using namespace std;
const int mxn = 64;
int bits[mxn + 2];
long long solve(long long n) {
  long long ret = 0;
  for (int i = 0, idx; i < mxn; ++i) {
    if (n >> i & 1) {
      for (idx = i; idx < mxn && bits[idx] == 0; ++idx)
        ;
      if (idx == mxn) return -1;
      for (; idx > i; --idx) bits[idx - 1] += 2, ++ret, --bits[idx];
      --bits[idx];
    }
    bits[i + 1] += bits[i] / 2;
  }
  return ret;
}
int main() {
  int tc, m;
  long long n, x;
  scanf("%d", &tc);
  while (tc--) {
    scanf("%lld%d", &n, &m);
    memset(bits, 0, sizeof(bits));
    for (int i = 1; i <= m; ++i) {
      scanf("%lld", &x);
      bits[__builtin_ctz(x)]++;
    }
    printf("%lld\n", solve(n));
  }
}
