#include <bits/stdc++.h>
using namespace std;
long long t, n, m;
int bits[100];
map<long long, int> logTwo;
int main() {
  for (int i = 0; i <= 60; i++) {
    long long a = pow(2, i);
    logTwo[a] = i;
  }
  cin >> t;
  while (t--) {
    memset(bits, 0, sizeof(bits));
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
      long long a;
      cin >> a;
      int loog = logTwo[a];
      bits[loog]++;
    }
    bitset<60> foo(n);
    int counter = 0;
    for (int i = 0; i < foo.size(); i++) {
      bool done = 1;
      if (foo.test(i)) {
        done = 0;
        long long a = pow(2, i);
        for (int j = i; j >= 0; j--) {
          long long b = pow(2, j);
          long long div = a / b;
          a = a - min(div * b, bits[j] * b);
        }
        if (a == 0) {
          a = pow(2, i);
          for (int j = i; j >= 0; j--) {
            long long b = pow(2, j);
            long long div = a / b;
            a = a - min(div * b, bits[j] * b);
            bits[j] -= min(bits[j], (int)div);
          }
          foo[i] = 0;
          done = 1;
          continue;
        }
        a = pow(2, i);
        int j;
        for (j = i; j <= 60; j++) {
          if (bits[j] == 0) {
            bits[j]++;
            counter++;
          } else {
            bits[j]--;
            foo[i] = 0;
            done = 1;
            break;
          }
        }
      }
      if (!done) {
        counter = -1;
        cout << -1 << endl;
        break;
      }
    }
    if (counter != -1) cout << counter << endl;
  }
}
