#include <bits/stdc++.h>   using namespace std;   using int64 = long long;   int64 bit_count(int64 n) {     int64 a{};     while (n) {       a += 1;       n >>= 1;     }     return a;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int T;     cin >> T;     while (T--) {       int64 n, m;       cin >> n >> m;       vector<int64> P(m);       for (auto &p : P) cin >> p;       auto s = accumulate(begin(P), end(P), 0ll);       if (s < n) {         cout << -1 <<   n ;         continue;       }       vector<int64> F(65);       for (auto p : P) F[bit_count(p) - 1]++;       int64 ans{};       for (int i = 0, j = -1; i < 64; i++) {         if (j >= 0 and F[i]) {           ans += i - j;           j = -1;           F[i]--;         }         if (n & (1 << i)) {           if (F[i]) {             F[i]--;           } else {             if (j == -1) j = i;           }         }         F[i + 1] += F[i] / 2;       }       cout << ans <<   n ;     }   }   