#include <bits/stdc++.h>
using namespace std;
vector<long long> cnt(61);
long long minDiv(long long n) {
  vector<long long> bin;
  long long i, j, k, x = n, y, ans = 0;
  while (x != 0) {
    if (x % 2 == 1)
      bin.push_back(1);
    else
      bin.push_back(0);
    x = x / 2;
  }
  for (i = 0; i < bin.size(); i++) {
    if (bin[i] == 1) {
      if (cnt[i] > 0)
        cnt[i] -= 1;
      else {
        for (j = i; j < 61; j++) {
          if (cnt[j] > 0) break;
        }
        ans = ans + j - i;
        while (j != i) {
          cnt[j] -= 1;
          cnt[j - 1] += 2;
          j--;
        }
        cnt[i] -= 1;
      }
    }
    cnt[i + 1] += (cnt[i] / 2);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t, n, i, j, k, s, m;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    s = 0;
    vector<long long> a(m);
    for (i = 0; i < 61; i++) {
      cnt[i] = 0;
    }
    for (i = 0; i < m; i++) {
      cin >> a[i];
      s += a[i];
    }
    sort(a.begin(), a.end());
    k = 0;
    j = 1;
    for (i = 0; i < m; i++) {
      while (a[i] != j) {
        j = j * 2;
        k++;
      }
      cnt[k]++;
    }
    if (s < n)
      cout << -1 << "\n";
    else
      cout << minDiv(n) << "\n";
  }
  return 0;
}
