#include <bits/stdc++.h>
using namespace std;
void solve();
void ioe() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
void solve() {
  long long n, m;
  cin >> n >> m;
  long long a[m];
  for (int i = 0; i < m; i++) cin >> a[i];
  int b[61];
  long long x = n;
  for (int i = 0; i < 61; i++) {
    b[i] = x % 2;
    x = x / 2;
  }
  int b1[61];
  for (int i = 0; i < 61; i++) b1[i] = 0;
  for (int i = 0; i < m; i++) {
    x = a[i];
    for (int j = 0; j < 61 && x != 0; j++) {
      b1[j] += x % 2;
      x = x / 2;
    }
  }
  int t = -1;
  int ans = 0;
  for (int i = 0; i < 60; i++) {
    if (t != -1 && b1[i] > 0) {
      b1[i]--;
      ans += i - t;
      t = -1;
    }
    if (b[i] > b1[i]) {
      if (t == -1) t = i;
    } else {
      b1[i] = b1[i] - b[i];
      b1[i + 1] += (b1[i] / 2);
    }
  }
  if (t != -1)
    cout << (-1) << "\n";
  else
    cout << ans << "\n";
}
