#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    int x;
    long long int sum = 0;
    int count[61];
    memset(count, 0, sizeof(count));
    for (int i = 0; i < m; i++) {
      cin >> x;
      sum += x;
      ++count[31 - __builtin_clz(x)];
    }
    if (sum < n) {
      cout << -1 << endl;
      continue;
    }
    long long int ans = 0;
    for (int i = 0; i < 60; i++) {
      if (n & (1ll << i)) {
        if (!count[i]) {
          int j = i + 1;
          while (!count[j]) j++;
          count[j]--;
          j = j - 1;
          while (j >= i) {
            count[j]++;
            ans++;
            j--;
          }
          count[i]++;
        }
        count[i]--;
      }
      count[i + 1] = count[i + 1] + count[i] / 2;
    }
    cout << ans << endl;
  }
  return 0;
}
