#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[70], b[70];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    long long n, num, sum = 0, x, ans = 0;
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    scanf("%lld%lld", &n, &num);
    for (int i = 1; i <= num; ++i) {
      scanf("%lld", &x), sum += x;
      for (int j = 0; j < 60; j++)
        if ((x >> j) & 1 == 1) {
          a[j]++;
          break;
        }
    }
    if (sum < n) {
      puts("-1");
      continue;
    }
    for (int j = 0; j < 60; j++)
      if ((n >> j) & 1 == 1) b[j]++;
    for (int i = 0; i < 60; ++i) {
      if (b[i] <= a[i])
        a[i + 1] += (a[i] - b[i]) / 2;
      else {
        for (int j = i + 1; j < 60; j++)
          if (a[j] != 0) {
            ans += j - i;
            a[j--]--;
            while (j > i) a[j--]++;
            break;
          }
      }
    }
    printf("%lld\n", ans);
  }
}
