#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
int T, odp;
long long n, sum;
int m;
long long pot[63];
map<long long, int> mapa;
bool ok;
vector<int> v;
int have[63], need[63];
void clean() {
  for (int i = 0; i <= 60; i++) {
    have[i] = 0;
    need[i] = 0;
  }
  v.clear();
  ok = 1;
  sum = 0;
  odp = 0;
}
void ini() {
  long long x = 1;
  for (int i = 0; i <= 60; i++) {
    pot[i] = x;
    mapa[x] = i;
    x *= 2;
  }
}
int main() {
  scanf("%d", &T);
  ini();
  for (int test = 1; test <= T; test++) {
    scanf("%lld%d", &n, &m);
    clean();
    v.reserve(m);
    for (int i = 1; i <= m; i++) {
      int a;
      scanf("%d", &a);
      sum += a;
      v.push_back(a);
    }
    if (sum < n) ok = 0;
    for (int i = 0; i < m; i++) {
      have[mapa[v[i]]]++;
    }
    for (int i = 60; i >= 0; i--) {
      if (n >= pot[i]) {
        need[i]++;
        n -= pot[i];
      }
    }
    for (int i = 0; i < 60; i++) {
      if (need[i]) {
        if (have[i] > 0) {
          have[i]--;
        } else {
          for (int j = i + 1; j < 60; j++) {
            if (have[j] > 0) {
              have[j]--;
              for (int z = j - 1; z >= i; z--) {
                have[z]++;
                odp++;
              }
              have[i]--;
              break;
            }
          }
        }
      }
      have[i + 1] += have[i] / 2;
    }
    if (ok)
      printf("%d\n", odp);
    else
      printf("-1\n");
  }
}
