#include <bits/stdc++.h>
using namespace std;
long long _x;
bool _f;
char _c;
inline long long rd() {
  _x = 0, _f = 1, _c = getchar();
  for (; !isdigit(_c); _c = getchar())
    if (_c == '-') _f = 0;
  for (; isdigit(_c); _c = getchar()) _x = _x * 10 + _c - '0';
  return _f ? _x : -_x;
}
template <typename T>
inline void chkmax(T& x, T y) {
  if (x < y) x = y;
}
template <typename T>
inline void chkmin(T& x, T y) {
  if (x > y) x = y;
}
const long long N = 1e5 + 10, G = 70;
long long a[N], p[G], n, m, sum;
bool g[G];
signed main() {
  for (long long T = rd(); T--;) {
    n = rd(), m = rd(), sum = 0;
    for (long long i = 1; i <= m; ++i) sum += (a[i] = rd());
    if (sum < n) {
      puts("-1");
      continue;
    }
    for (long long i = 1; i <= m; ++i)
      for (long long j = 0; j <= 30; ++j)
        if (a[i] == (1 << j)) {
          ++p[j];
          break;
        }
    long long t = 0;
    while (n) {
      if (n & 1) g[t] = 1;
      ++t, n >>= 1;
    }
    long long zq = 0, ans = 0;
    for (long long i = 0; i <= 60; ++i) {
      if (zq) {
        if (p[i])
          --p[i], ans += zq, zq = 0;
        else
          ++zq;
      }
      if (g[i]) {
        if (p[i])
          --p[i];
        else if (!zq)
          zq = 1;
      }
      p[i + 1] += p[i] >> 1;
    }
    printf("%d\n", ans);
    memset(p, 0, sizeof p), memset(g, 0, sizeof g);
  }
  return 0;
}
