#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<
                                    !is_same<T_container, string>::value,
                                    typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v) {
  os << '{';
  string sep;
  for (const T &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
template <typename T>
void dbg_a(T *a, int l, int r) {
  cerr << " {";
  for (int i = l; i < r; i++) cerr << a[i] << ", ";
  cerr << a[r] << "}" << endl;
}
inline long long read() {
  long long f(1), r(0);
  char c(getchar());
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    r = (r << 1) + (r << 3) + c - '0';
    c = getchar();
  }
  return f * r;
}
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long N = 2e5 + 6, M = N * 2 + 6;
const long long mod = 2017;
long long n, m, q;
long long a[N];
long long b[100], bn[100];
void solve() {
  n = read();
  m = read();
  long long sum = 0;
  memset(b, 0, sizeof(b));
  memset(bn, 0, sizeof(bn));
  for (long long i = 1; i <= m; i++) {
    long long x = read();
    sum += x;
    for (long long j = 0; j <= 30; j++)
      if (x & (1ll << j)) b[j]++;
  }
  for (long long i = 0; i <= 62; i++)
    if (n & (1ll << i)) bn[i]++;
  if (sum < n) {
    cout << -1 << "\n";
    return;
  }
  long long ans = 0;
  for (long long i = 0; i <= 62; i++) {
    if (bn[i]) {
      if (!b[i]) {
        long long pre = i + 1;
        while (!b[pre]) pre++;
        for (long long k = pre; k >= i + 1; k--) {
          b[k]--;
          b[k - 1] += 2;
          ans++;
        }
      }
      b[i]--;
    }
    b[i + 1] += b[i] / 2;
  }
  cout << ans << "\n";
}
signed main() {
  long long T = 1;
  T = read();
  while (T--) solve();
  return 0;
}
