#include <bits/stdc++.h>
const int M = 1e9 + 7, N = 2 * 1e5 + 3;
using namespace std;
long long n, m, a[42], x, ans, t;
void solve() {
  ans = 0;
  cin >> n >> m;
  memset(a, 0, sizeof(a));
  for (int i = 0, k; i < m; i++) {
    cin >> x;
    k = 0;
    while (x % 2 == 0) x /= 2, k++;
    a[k]++;
  }
  for (long long i = 0; i < 41; i++) {
    t = 1;
    for (int l = 1; l <= i; l++) t *= 2;
    if (n & t) {
      if (a[i] > 0)
        a[i]--;
      else {
        bool q = 0;
        for (long long j = i + 1; j < 41; j++) {
          if (a[j]) {
            ans += j - i, a[j]--, q = 1;
            for (long long l = j - 1; l > i; l--) a[l] = 1;
            break;
          }
        }
        if (!q) {
          cout << "-1\n";
          return;
        }
      }
    }
    a[i + 1] += a[i] / 2;
  }
  cout << ans << "\n";
  return;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
