#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:33554432")
void dout() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
  std::cerr << H << ' ';
  dout(T...);
}
using ll = long long;
using ld = long double;
const int MAXPRECISION = 20;
void precalc() {}
using namespace std;
map<int, int> mp;
void solve() {
  int t;
  cin >> t;
  while (t--) {
    mp.clear();
    ll n, m;
    cin >> n >> m;
    ll s = 0;
    for (int i = 0; i < m; ++i) {
      ll a;
      cin >> a;
      int pow = 0;
      s += a;
      while (a) {
        a /= 2;
        ++pow;
      }
      pow -= 1;
      mp[pow]++;
    }
    if (s < n) {
      cout << "-1\n";
      continue;
    }
    ll answr = 0;
    int pw = 0;
    while (n) {
      if (n % 2) {
        if (mp[pw] == 0) {
          int nxt = pw + 1;
          while (mp[nxt] == 0) {
            mp[nxt] = 1;
            nxt++;
          }
          mp[nxt] -= 1;
          answr += nxt - pw;
        } else {
          mp[pw]--;
        }
      }
      mp[pw + 1] += mp[pw] / 2;
      n /= 2;
      pw++;
    }
    cout << answr << "\n";
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr), std::cout.tie(nullptr);
  std::cout << std::fixed << std::setprecision(MAXPRECISION);
  precalc();
  solve();
}
