#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long cas;
  scanf("%lld", &cas);
  while (cas--) {
    long long res[64];
    memset(res, 0, sizeof(res));
    long long n, m;
    cin >> n >> m;
    long long sum = 0;
    for (long long i = 0; i < m; i++) {
      long long t;
      scanf("%lld", &t);
      long long tmp = 0;
      sum += t;
      while (t) {
        if (t & 1) res[tmp]++;
        t >>= 1;
        tmp++;
      }
    }
    long long tmp = 0;
    long long ans = 0;
    if (sum < n) {
      cout << -1 << endl;
      continue;
    }
    while (n) {
      if (n & 1) {
        if (res[tmp]) {
          res[tmp]--;
          res[tmp + 1] += res[tmp] / 2;
        } else {
          for (long long i = tmp; i < 64; i++) {
            if (res[i]) {
              res[i]--;
              ans += (i - tmp);
              n >>= (i - tmp);
              tmp = i;
              break;
            }
          }
          continue;
        }
      } else {
        res[tmp + 1] += res[tmp] / 2;
      }
      n >>= 1;
      tmp++;
    }
    cout << ans << endl;
  }
  return 0;
}
