#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const int N = (int)1e6 + 7;
const int M = (int)-1;
int a[N], cnt[100];
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long n;
    int m;
    cin >> n >> m;
    for (int i = (0); i < (m); ++i) cin >> a[i];
    long long sum = 0;
    for (int i = (0); i < (m); ++i) sum += a[i];
    if (sum < n) {
      cout << -1 << endl;
      continue;
    }
    sort(a, a + m);
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0, j = 0; i < m; i++) {
      while (a[i] > (1ll << j)) j++;
      cnt[j]++;
    }
    long long res = 0;
    int ans = 0;
    for (int i = (0); i < (63); ++i) {
      if (n >> i & 1) {
        if (!cnt[i] && res < (1ll << i)) {
          int j = i + 1;
          cnt[i] = 2;
          while (!cnt[j]) {
            cnt[j]++;
            j++;
            ans++;
          }
          cnt[j]--;
          ans++;
        }
        if (cnt[i])
          cnt[i]--;
        else
          res -= 1ll << i;
      }
      res += (1ll << i) * cnt[i];
    }
    cout << ans << endl;
  }
  return 0;
}
