#include <bits/stdc++.h>
using namespace std;
long long p[65];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long T;
  cin >> T;
  while (T--) {
    for (long long i = 0; i < 65; i++) p[i] = 0;
    long long n, m;
    cin >> n >> m;
    long long pi = 65;
    for (long long i = 0; i < m; i++) {
      long long t, p2;
      cin >> t;
      p2 = -1;
      for (; t; t /= 2) p2++;
      p[p2]++;
      pi = min(pi, p2);
    }
    long long res = 0;
    for (long long p2 = 0; (1LL << p2) <= n; p2++)
      if (n & (1LL << p2)) {
        while (pi < p2) {
          p[pi + 1] += p[pi] / 2;
          p[pi] = 0;
          pi++;
        }
        while (p[pi] == 0 && pi + 1 < 65) pi++;
        while (p[pi] > 0 && pi > p2) {
          p[pi]--;
          p[pi - 1] += 2;
          res++;
          pi--;
        }
        if (p[pi] == 0) {
          res = -1;
          break;
        }
        p[pi]--;
      }
    cout << res << "\n";
  }
}
