#include <bits/stdc++.h>
using namespace std;
int kek[50];
int eke[100];
long long n;
int yikes() {
  int bored = 0;
  while (n > 0) {
    if (n % 2 == 1) {
      eke[bored] = 1;
    }
    n /= 2;
    bored++;
  }
  return bored;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int m, temp, hmm, rip = 0, arns = 0;
    memset(kek, 0, sizeof(kek));
    memset(eke, 0, sizeof(eke));
    scanf("%lld%d", &n, &m);
    for (int i = 0; i < m; i++) {
      scanf("%d", &temp);
      kek[31 - __builtin_clz(temp)]++;
    }
    hmm = yikes();
    for (int i = 0; i < hmm; i++) {
      if (eke[i] == 1 && kek[i] > 0) {
        kek[i]--;
        eke[i] = 0;
      }
      if (eke[i] == 1 && kek[i] == 0) {
        temp = -1;
        for (int k = i + 1; k < 40; k++) {
          if (kek[k] > 0) {
            temp = k;
            break;
          }
        }
        if (temp == -1) {
          rip = 1;
          break;
        }
        arns += temp - i;
        kek[temp]--;
        i = temp - 1;
        continue;
      }
      kek[i + 1] += kek[i] / 2;
    }
    if (rip == 1) {
      printf("-1\n");
      continue;
    }
    printf("%d\n", arns);
  }
}
