#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
long long n;
int t, m, a[maxn], cnt[70];
int main() {
  scanf("%d", &t);
  while (t--) {
    memset(cnt, 0, sizeof(cnt));
    long long sum = 0;
    scanf("%lld%d", &n, &m);
    for (int i = 0; i < m; i++) {
      scanf("%d", &a[i]);
      sum += a[i];
    }
    if (sum < n)
      printf("-1\n");
    else if (sum == n)
      printf("0\n");
    else {
      int ans = 0;
      bool flag = 1;
      for (int i = 0; i < m; i++) cnt[(int)(log2(a[i]) + 0.5)]++;
      for (long long i = 1, j = 0; i <= n && flag; i <<= 1, ++j) {
        if (n & i) {
          if (cnt[j])
            --cnt[j];
          else {
            bool tag = 0;
            for (int k = j + 1; k < 60; k++) {
              if (cnt[k]) {
                tag = 1, --cnt[k], ans += k - j;
                while (--k > j) ++cnt[k];
                break;
              }
            }
            flag = tag;
          }
        }
        cnt[j + 1] += cnt[j] >> 1;
      }
      if (!flag) ans = -1;
      printf("%d\n", ans);
    }
  }
  return 0;
}
