#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 100;
int a[N], cnt[100];
int get_num(int num) {
  int ans = 0;
  while (num) {
    ans++;
    num >>= 1;
  }
  return ans - 1;
}
int main() {
  int w;
  cin >> w;
  while (w--) {
    memset(cnt, 0, sizeof(cnt));
    long long n, m;
    scanf("%lld%lld", &n, &m);
    long long sum = 0;
    for (int i = 1; i <= m; i++) {
      scanf("%d", a + i);
      cnt[get_num(a[i])]++;
      sum += a[i];
    }
    if (sum < n) {
      printf("-1\n");
      continue;
    }
    vector<int> bit;
    while (n) {
      bit.push_back(n % 2);
      n >>= 1;
    }
    int ans = 0;
    for (int i = 0; i < bit.size(); i++) {
      if (bit[i]) {
        int pos = i;
        if (!cnt[pos]) {
          while (!cnt[pos]) {
            cnt[pos]++;
            pos++;
            ans++;
          }
          cnt[pos]--;
          cnt[i]++;
        }
        cnt[i]--;
      }
      cnt[i + 1] += cnt[i] / 2;
    }
    printf("%d\n", ans);
  }
  return 0;
}
