#include <bits/stdc++.h>
using namespace std;
int t, m, a[100010];
long long n;
int main() {
  cin.tie(0), ios_base::sync_with_stdio(0);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    long long sum = 0;
    for (int i = 0; i < m; ++i) {
      cin >> a[i];
      sum += a[i];
    }
    if (sum < n) {
      cout << "-1\n";
    } else {
      sort(a, a + m);
      int cnt[70] = {0}, p = 0, pNum = 1;
      for (int i = 0; i < m; ++i) {
        while (pNum < a[i]) ++p, pNum <<= 1;
        ++cnt[p];
      }
      long long d = 0, num = 1, ans = 0;
      while (num <= n) {
        if ((n & num) == 0) {
          cnt[d + 1] += cnt[d] / 2;
        } else {
          if (cnt[d]) {
            --cnt[d];
          } else {
            long long idx = d;
            while (idx < 70 && !cnt[idx]) ++idx;
            if (idx == 70) break;
            while (idx > d) {
              --cnt[idx];
              cnt[idx - 1] += 2;
              ++ans;
              --idx;
            }
            --cnt[idx];
          }
          cnt[d + 1] += cnt[d] / 2;
        }
        ++d, num <<= 1;
      }
      cout << ans << "\n";
    }
  }
}
