#include <bits/stdc++.h>
using namespace std;
int cnt[65];
int find(int x) {
  for (int i = 0; i <= 32; i++) {
    if ((x >> i) & 1) return i;
  }
  return 33;
}
int main(void) {
  int T;
  scanf("%d", &T);
  while (T--) {
    long long n;
    int m;
    scanf("%I64d%d", &n, &m);
    memset(cnt, 0, sizeof(cnt));
    long long sum = 0;
    for (int i = 1; i <= m; i++) {
      int x;
      scanf("%d", &x);
      cnt[find(x)]++;
      sum += x;
    }
    if (sum < n) {
      printf("-1\n");
      continue;
    }
    int res = 0;
    for (int i = 0; i <= 63; i++) {
      if ((n >> i) & 1) {
        if (cnt[i] != 0)
          cnt[i]--;
        else {
          for (int j = i + 1; j <= 63; j++) {
            res++;
            if (cnt[j] != 0) {
              cnt[j]--;
              break;
            } else {
              cnt[j]++;
            }
          }
        }
      }
      cnt[i + 1] += cnt[i] / 2;
    }
    printf("%d\n", res);
  }
  return 0;
}
