#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
int64 bits(int64 n) {
  int64 a{};
  while (n) {
    a++;
    n /= 2;
  }
  return a;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    int64 n, m, p, s{}, a{}, f{};
    cin >> n >> m;
    vector<int64> F(65);
    while (m--) {
      cin >> p;
      s += p;
      F[bits(p) - 1]++;
    }
    if (s < n) {
      cout << -1 << '\n';
      continue;
    }
    for (int i = 0, j = -1; i < 64; i++) {
      a += f;
      if (F[i]) {
        F[i] -= f;
        f = 0;
      }
      if (n & (1ll << i)) {
        if (F[i])
          F[i]--;
        else
          f = 1;
      }
      F[i + 1] += F[i] / 2;
    }
    cout << a << '\n';
  }
}
