#include <bits/stdc++.h>
const int MaxN = 2e5 + 10;
const int MaxC = 30 + 10;
using namespace std;
inline long long read() {
  long long cnt = 0, opt = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') opt = 0;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    cnt = (cnt << 3) + (cnt << 1) + (ch ^ 48);
  return opt ? cnt : -cnt;
}
long long a[MaxN], total[MaxC];
int main() {
  int T;
  T = read();
  while (T--) {
    long long n, m;
    m = read(), n = read();
    for (int i = 0; i <= 30; ++i) total[i] = 0;
    long long chzhc_sum = 0, answer = 0;
    for (long long i = 1; i <= n; ++i) {
      a[i] = read();
      long long now = a[i], tot = 0;
      while (now > 1) tot++, now >>= 1;
      total[tot]++;
      chzhc_sum += a[i];
    }
    if (m > chzhc_sum) {
      printf("-1\n");
      continue;
    }
    chzhc_sum = 0;
    for (int i = 0; i <= 30; ++i) {
      if ((1 << i) & m) chzhc_sum--;
      if (chzhc_sum < 0) {
        long long k;
        for (k = i; !total[k]; k++) total[k] = 1;
        total[k]--;
        answer += k - i;
        chzhc_sum = 0;
      }
      chzhc_sum += total[i];
      chzhc_sum >>= 1;
    }
    printf("%lld\n", answer);
  }
  return 0;
}
