#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL)->sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    long long n;
    int m;
    cin >> n >> m;
    map<long long, int> box;
    long long mx = 0;
    long long sum = 0;
    int x;
    while (m--) {
      cin >> x;
      sum += x;
      box[x] += 1;
    }
    if (sum < n) {
      cout << "-1\n";
      continue;
    }
    for (int i = 0; i < 64; ++i) {
      long long dr = 1LL << i;
      if (dr & n) {
        auto rt = box.lower_bound(dr);
        long long dt = rt->first;
        if (dt > dr) {
          rt->second -= 2;
          box[dr] += 1;
          while (dt >= dr) {
            mx += 1;
            box[dt] += 1;
            dt >>= 1;
          }
          mx -= 1;
        }
        box[dr] -= 1;
        if (rt->second == 0) box.erase(rt);
      }
      if (box[dr] /= 2) box[2 * dr] += box[dr];
    }
    cout << mx << '\n';
  }
  return 0;
}
