#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long maxn = 500005;
const long long mm = 1e+18;
long long power(long long x, long long y) {
  long long res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res;
}
long long fii(long long arr[], long long t) {
  for (long long i = t; i < 70; i++)
    if (arr[i]) return i;
  return -1;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  long long arr[70];
  memset(arr, 0, sizeof(arr));
  for (long long i = 0; i < m; i++) {
    long long x;
    cin >> x;
    long long t = 0;
    while (x) {
      t++;
      x >>= 1;
    }
    arr[t]++;
  }
  long long t = 0;
  long long an = 0;
  while (n) {
    t++;
    if (n & 1) {
      long long x = fii(arr, t);
      if (x == -1) {
        cout << -1;
        return;
      }
      arr[x]--;
      an += (x - t);
      for (long long i = t; i < x; i++) arr[i]++;
    }
    n >>= 1;
    arr[t + 1] += (arr[t]) / 2;
  }
  cout << an;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
