#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int maxn = 1e4 + 10;
int f[200050];
int vis[200050];
double F[1000050];
int a[100], b[100];
map<char, char> visR, visL;
char key[100];
void er(long long n, int k[]) {
  while (n) {
    long long u = 1, i = 0;
    while (u * 2 <= n) {
      u *= 2;
      i++;
    }
    n -= u;
    k[i]++;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    long long n, m;
    cin >> n >> m;
    er(n, a);
    int len;
    for (int i = 0; i < 70; i++)
      if (a[i]) len = i + 1;
    long long x, s = 0;
    for (int i = 0; i < m; i++) {
      cin >> x;
      s += x;
      er(x, b);
    }
    if (s < n)
      cout << -1 << endl;
    else {
      int ans = 0;
      for (int i = 0; i < len; i++) {
        if (a[i] <= b[i]) {
          b[i] -= a[i];
          if (b[i] >= 2) b[i + 1] += b[i] / 2;
        } else {
          for (int j = i + 1; j < 70; j++) {
            if (b[j]) {
              b[j]--;
              for (int k = j - 1; k >= i; k--) {
                b[k]++;
                ans++;
              }
              break;
            }
          }
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}
