#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long num1[70], num2[70];
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 0; i <= 60; ++i) {
      num1[i] = num2[i] = 0;
    }
    long long x;
    long long sum = 0;
    for (int i = 0; i < m; ++i) {
      cin >> x;
      sum += x;
      for (long long j = 0; j <= 60; ++j) {
        if (x & (1ll << j)) {
          ++num1[j];
        }
      }
    }
    for (long long j = 0; j <= 60; ++j) {
      if (n & (1ll << j)) {
        num2[j] = 1;
      }
    }
    if (sum < n) {
      cout << -1 << "\n";
      continue;
    }
    sum = 0;
    for (int i = 0; i <= 60; ++i) {
      if (num1[i] && num2[i]) {
        num1[i] -= 1;
        num2[i] = 0;
      }
    }
    int ans = 0;
    for (long long i = 0; i <= 60; ++i) {
      sum += ((long long)num1[i] * (1ll << i));
      if (num2[i]) {
        if (sum >= (1ll << i)) {
          sum -= (1ll << i);
          num2[i] = 0;
        } else {
          long long j = i + 1;
          for (j; !num1[j]; ++j)
            ;
          num1[j] -= 1;
          for (long long k = j - 1; k >= i; --k) {
            ++ans;
            ++num1[k];
          }
          sum += (1ll << i);
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
