#include <bits/stdc++.h>
using namespace std;
int T, m, c[110], ans;
long long n, a, sum, num[110];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%lld %d", &n, &m);
    sum = 0;
    ans = 0;
    memset(num, 0, sizeof num);
    memset(c, 0, sizeof c);
    for (int i = 1; i <= m; i++) {
      scanf("%lld", &a);
      sum += a;
      int cnt = -1;
      while (a) {
        cnt++;
        a >>= 1;
      }
      num[cnt]++;
    }
    if (sum < n) {
      printf("-1\n");
      continue;
    }
    int cnt = 0;
    while (n) {
      c[cnt] = (n & 1);
      n >>= 1;
      cnt++;
    }
    for (int i = 0; i <= 60; i++) {
      if (c[i]) {
        if (num[i]) {
          num[i]--;
        } else {
          for (int j = i + 1; j <= 60; j++) {
            if (num[j]) {
              num[j]--;
              num[i] += (1 << (j - i));
              ans += j - i;
              break;
            }
          }
          num[i]--;
        }
      }
      num[i + 1] += (num[i] >> 1);
    }
    printf("%d\n", ans);
  }
  return 0;
}
