#include <bits/stdc++.h>
#pragma GCC optimisze("Ofast")
#pragma GCC optimisze("O3")
#pragma GCC optimisze("unroll-loops")
using namespace std;
const long long inf = 1e17;
long long num(long long x) {
  for (int i = 0; i < 67; i++) {
    if (x == 1 << i) return i;
  }
}
int main() {
  long long q;
  cin >> q;
  while (q--) {
    long long n, carryn, ans = 0, sum = 0;
    cin >> carryn >> n;
    vector<long long> a(70, 0);
    for (int i = 0; i < n; i++) {
      long long x;
      cin >> x;
      sum += x;
      a[num(x)]++;
    }
    n = carryn;
    if (sum < n) {
      cout << "-1\n";
      continue;
    }
    vector<long long> nr;
    while (n > 0) {
      nr.push_back(n % 2);
      n /= 2;
    }
    n = carryn;
    vector<long long> otha(70, 0);
    while (nr.size() != 70) nr.push_back(0);
    for (int i = 0; i < 67; i++) {
      if (nr[i] == 1) otha[i]--;
      if (otha[i] < 0) a[i]--, otha[i]++;
      if (a[i] > 1) {
        otha[i + 1] += a[i] / 2;
        a[i] %= 2;
      }
      if (otha[i] > 1) {
        otha[i + 1] += otha[i] / 2;
        otha[i] %= 2;
      }
      if (otha[i] == 1 && a[i] == 1) {
        otha[i] = a[i] = 0;
        otha[i + 1]++;
      }
      while (a[i] < 0) {
        a[i] += 2;
        a[i + 1]--;
        ans++;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
