#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int N = 5e2 + 10;
const int M = 4e4 + 10;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int mod2 = 998244853;
int bit[100];
signed main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    memset(bit, 0, sizeof(bit));
    long long n, m;
    cin >> n >> m;
    long long sum = 0;
    long long x;
    for (long long i = 1; i <= m; i++) {
      cin >> x;
      sum += x;
      long long cnt = 0;
      while (x > 1) {
        x >>= 1;
        cnt++;
      }
      bit[cnt]++;
    }
    long long ans = 0;
    if (sum < n) {
      cout << "-1" << endl;
    } else {
      vector<long long> v;
      for (long long i = 0;; i++) {
        v.push_back(n % 2);
        if (n % 2) {
          if (bit[i]) {
            bit[i]--;
          } else {
            long long j = i + 1;
            while (!bit[j]) j++;
            bit[j] -= 1;
            ans += j - i;
            j--;
            while (j >= i) {
              bit[j--] += 1;
            }
          }
        }
        n /= 2;
        bit[i + 1] += bit[i] / 2;
        if (!n) break;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
