func_code_string: #include <bits/stdc++.h>   void rd(int &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   void lrd(long long &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   const int INF = 1e9;   const long long LINF = 1e18;   const int inf = 1e5 + 10;   using namespace std;   int T;   long long n;   int m, a[inf];   int cnt[100];   map<int, int> S;   int sta[100], top;   int main() {     rd(T);     int now = 1;     for (int i = 0; i <= 30; i++) S[now] = i, now *= 2;     while (T--) {       lrd(n);       rd(m);       memset(cnt, 0, sizeof(cnt));       long long sum = 0;       for (int i = 1; i <= m; i++) rd(a[i]), cnt[S[a[i]]]++, sum += a[i];       if (sum < n)         printf( -1 n );       else {         int now = 0;         top = 0;         while (n) {           if (n & 1) {             if (cnt[now])               cnt[now]--;             else               sta[++top] = now;           }           now++;           n /= 2;         }         int ans = 0;         for (int i = 1; i <= top;) {           for (int j = 0; j < sta[i]; j++) cnt[j + 1] += cnt[j] / 2, cnt[j] %= 2;           for (int j = sta[i]; j <= 99; j++) {             if (cnt[j]) {               ans += j - sta[i];               cnt[j]--;               for (int k = sta[i]; k < j; k++) cnt[k]++;               while (i <= top && sta[i] <= j) i++;               break;             }           }         }         printf( %d n , ans);       }     }     return 0;   }   