#include <bits/stdc++.h>
using namespace std;
long long m, n;
int main() {
  long long i, j, test, cn = 0;
  long long a, b, t, x;
  long long rp[77], ap[77];
  scanf("%lld", &test);
  while (test--) {
    scanf("%lld %lld", &n, &m);
    memset(rp, 0, sizeof(rp));
    memset(ap, 0, sizeof(ap));
    for (i = 0; i < 64; i++) {
      if ((bool)(n & (1LL << i))) rp[i]++;
    }
    long long s = 0;
    for (j = 0; j < m; j++) {
      scanf("%lld", &x);
      s += x;
      for (i = 0; i < 64; i++) {
        if ((bool)(x & (1LL << i))) {
          ap[i]++;
          break;
        }
      }
    }
    if (s < n) {
      puts("-1");
      continue;
    }
    cn = 0;
    for (i = 0; i < 63; i++) {
      if (rp[i]) {
        if (ap[i] == 0) {
          for (j = i + 1; j < 63; j++) {
            if (ap[j]) {
              break;
            }
          }
          for (; j > i; j--) {
            ap[j]--;
            cn++;
            ap[j - 1] += 2;
          }
        }
        ap[i]--;
      }
      ap[i + 1] += ap[i] / 2;
    }
    printf("%lld\n", cn);
  }
  return 0;
}
