#include <bits/stdc++.h>
using namespace std;
bitset<60> bit;
const int N = 1e5 + 7;
const int MOD = 1e9 + 7;
const double PI = atan(1.0) * 4;
const int maxn = 3e5 + 5;
int c[N];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    memset(c, 0, sizeof(c));
    long long n, m;
    scanf("%lld %lld", &n, &m);
    long long sum = 0;
    for (int i = 1; i <= m; i++) {
      long long x;
      scanf("%lld", &x);
      sum += x;
      for (int j = 0; j < 60; j++) {
        if ((x >> j) & 1 == 1) {
          c[j]++;
        }
      }
    }
    if (sum < n) {
      printf("%d\n", -1);
      continue;
    }
    long long ans = 0;
    for (int i = 0; i < 60; i++) {
      if ((n >> i) & 1) {
        if (!c[i]) {
          for (int j = i + 1; j < 70; j++) {
            if (c[j]) {
              c[j]--;
              int now = j;
              while (now != i) {
                now = now - 1;
                c[now]++;
                ans++;
              }
              c[now]++;
              break;
            }
          }
        }
        c[i]--;
      }
      c[i + 1] += c[i] / 2;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
