#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
const long long mod = 998244353;
const long long inf = 1ll << 60;
const long long maxn = 100005;
signed main() {
  long long T;
  cin >> T;
  while (T--) {
    long long n, k, sum = 0;
    cin >> k >> n;
    vector<long long> vc(n), bin, cnt(maxn);
    for (long long i = (0); i < (n); i++) {
      cin >> vc[i];
      sum += vc[i];
      long long j = log2(vc[i]);
      cnt[j]++;
    }
    if (sum < k) {
      cout << -1 << '\n';
      continue;
    }
    long long ans = 0;
    long long i = 0;
    while (k > 0) {
      if (k & 1) {
        if (cnt[i] == 0) {
          ;
          long long cc = i;
          for (long long j = (i); j < (31); j++) {
            if (cnt[j] > 0) {
              cnt[j]--;
              cc = j;
              break;
            }
            cnt[j] = 1;
          }
          ans += cc - i;
          k >>= 1;
          i++;
          continue;
        }
        cnt[i]--;
      }
      cnt[i + 1] += cnt[i] / 2;
      i++;
      k >>= 1;
      ;
    }
    cout << ans << '\n';
  }
}
