#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, ff = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') ff = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return x * ff;
}
long long ans, a[100005];
signed main() {
  long long t, m, n, x;
  unsigned long long s;
  t = read();
  while (t--) {
    m = read();
    n = read();
    ans = 0;
    s = 0;
    for (register long long i = 1; i <= n; i++) a[i] = read(), s += a[i];
    if (s < m) {
      puts("-1");
      continue;
    }
    for (register long long i = 1; i <= n; i++) {
      long long u = -1;
      while (a[i]) {
        a[i] /= 2;
        u++;
      }
      a[i] = u;
    }
    sort(a + 1, a + n + 1);
    long long u = 1;
    s = 0;
    for (register long long i = 0; (1ll << i) <= m; i++) {
      if (!(m & (1ll << i))) continue;
      long long l = u;
      u = lower_bound(a + u, a + n + 1, i) - a;
      if (a[u] == i) {
        for (register long long j = l; j < u; j++) s += (1ll << a[j]);
        u = u + 1;
        continue;
      }
      for (register long long j = l; j < u; j++) {
        s += (1ll << a[j]);
      }
      if (s >= (1ll << i))
        s -= (1ll << i);
      else {
        ans += a[u] - i;
        s += (1ll << a[u]) - (1ll << i);
        u = u + 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
