#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int w;
  cin >> w;
  vector<long long int> po(62);
  map<long long int, long long int> ind;
  long long int j = 0;
  for (long long int i = 1; i <= 1e18; i *= 2) {
    po[j] = i;
    ind[i] = j++;
  }
  while (w--) {
    long long int n, m;
    cin >> n >> m;
    vector<long long int> v(m), cou(62, 0);
    long long int t = 0;
    for (long long int i = 0; i <= m - 1; i++) {
      cin >> v[i];
      t += v[i];
      cou[ind[v[i]]]++;
    }
    if (t < n) {
      cout << "-1" << '\n';
      continue;
    }
    vector<long long int> bin(62, 0);
    long long int i = 0;
    while (n > 0) {
      bin[i] = n % 2;
      i++;
      n /= 2;
    }
    long long int temp = 0;
    long long int ans = 0;
    for (long long int i = 0; i <= 61; i++) {
      if (bin[i] == 1) {
        if (temp >= po[i]) {
          temp -= po[i];
        } else if (cou[i] > 0) {
          cou[i]--;
        } else {
          long long int u;
          for (long long int j = i + 1; j <= 62; j++) {
            if (cou[j] > 0) {
              u = j;
              break;
            }
          }
          cou[u]--;
          for (long long int j = u - 1; j >= i; j--) {
            cou[j]++;
            ans++;
          }
        }
      }
      temp += (cou[i] * po[i]);
    }
    cout << ans << '\n';
  }
  return 0;
}
