#include <bits/stdc++.h>
using namespace std;
template <typename T>
string toString(T n) {
  stringstream ss;
  ss << n;
  string s;
  ss >> s;
  return s;
}
void init() {
  cout << fixed << setprecision(0);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
void printAll(int n, ...) {
  va_list ap;
  va_start(ap, n);
  for (int i = 1; i <= n; i++) cout << va_arg(ap, long long int) << " ";
  cout << endl;
  va_end(ap);
}
bool isInteger(double n) {
  if (n - (long long int)n == 0)
    return true;
  else
    return false;
}
int main() {
  init();
  long long int i, j, k, l, r, n;
  int t;
  scanf("%d", &t);
  ;
  while (t--) {
    int m;
    scanf("%lli", &n);
    scanf("%d", &m);
    vector<int> ara(m);
    vector<int> count(64, 0);
    long long int sum = 0;
    for (i = 0; i < m; i++) {
      scanf("%d", &ara[i]);
      count[log2(ara[i])]++;
      sum += ara[i];
    }
    if (sum < n) {
      printf("-1\n");
      continue;
    }
    if (0) {
      int q;
      for (q = 0; q < 13; q++) cout << count[q] << " ";
      cout << endl;
    };
    long long int ans = 0;
    int size = log2(n) + 2;
    for (i = 0; i < size; i++) {
      if (n & (1LL << i)) {
        if (count[i] == 0) {
          for (j = i + 1; j < 64; j++) {
            ans++;
            if (count[j] > 0) break;
          }
          count[j]--;
          count[j - 1] = 2;
          for (j = j - 2; j >= i; j--) {
            count[j + 1]--;
            count[j] += 2;
            if (0) {
              int q;
              for (q = 0; q < 13; q++) cout << count[q] << " ";
              cout << endl;
            };
          }
        }
        count[i]--;
      }
      if (count[i] > 0) {
        count[i + 1] += count[i] / 2;
        count[i] -= (count[i] - count[i] % 2);
      }
      if (0) {
        int q;
        for (q = 0; q < 13; q++) cout << count[q] << " ";
        cout << endl;
      };
    }
    printf("%lli\n", ans);
  }
  return 0;
}
