#include <bits/stdc++.h>
using namespace std;
const int MX = 65;
int have[MX];
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    memset(have, 0, sizeof(have));
    long long n;
    int m, ai;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
      cin >> ai;
      have[(int)log2(ai)]++;
    }
    long ans = 0;
    for (int i = 0; (long long)(1LL << i) <= n; i++) {
      long long cur = (long long)(1LL << i);
      if (!(n & cur)) continue;
      for (int j = 0; (j < i) && (j < MX); j++) {
        have[j + 1] += have[j] / 2;
        have[j] &= 1;
      }
      if (have[i]) {
        have[i]--;
        n &= ~cur;
      } else {
        for (int j = i + 1; j < MX; j++) {
          if (!have[j]) continue;
          have[j]--;
          for (int k = j - 1; k >= i; k--) {
            ans++;
            have[k]++;
          }
          n &= ~(1LL << i);
          break;
        }
      }
    }
    if (n)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
