#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
long long rd() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int a[N], c[100], b[100];
void solve() {
  long long n, sum = 0;
  int m;
  n = rd();
  m = rd();
  memset(c, 0, sizeof(c));
  memset(b, 0, sizeof(b));
  for (int i = 1; i <= m; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
    int x = a[i], len = 0;
    while (x) {
      ++len;
      x /= 2;
    }
    c[len]++;
  }
  if (sum < n) {
    printf("-1\n");
    return;
  }
  int len = 0;
  while (n) {
    b[++len] = n % 2;
    n /= 2;
  }
  for (int i = 1; i <= len; i++) {
    if (b[i] == 1 && c[i] != 0) {
      b[i] = 0;
      c[i]--;
    }
  }
  long long su = 0, ans = 0;
  for (int i = 1; i <= len; i++) {
    su += 1ll * (1 << i) * c[i];
    if (b[i] == 1 && su < (1 << i)) {
      for (int j = i + 1; j <= 100; j++) {
        if (c[j] != 0) {
          c[j]--;
          for (int k = i + 1; k <= j - 1; k++) c[k]++;
          ans += j - i;
          su = su + (1 << i);
          break;
        }
      }
    } else if (b[i] == 1)
      su -= (1 << i);
  }
  printf("%lld\n", ans);
}
int main() {
  for (int _ = rd(); _ >= 1; _--) solve();
}
