#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<int, ii>;
using vi = vector<int>;
using vii = vector<ii>;
void solve() {
  ll rem, m;
  cin >> rem >> m;
  vector<int> boxes(m);
  ll sum = 0;
  for (int i = 0; i < m; i++) {
    cin >> boxes[i];
    sum += boxes[i];
  }
  if (sum < rem) {
    cout << "-1\n";
    return;
  }
  sort(boxes.begin(), boxes.end(), greater<int>());
  ll power = 1;
  sum = 0;
  int cnt = 0;
  while (rem) {
    if (power & rem) {
      if (sum < power) {
        ll smallest = boxes.back();
        if (smallest > power) {
          boxes.pop_back();
          boxes.push_back(smallest / 2);
          boxes.push_back(smallest / 2);
          cnt++;
        } else {
          sum += smallest;
          boxes.pop_back();
        }
      } else {
        sum -= power;
        rem -= power;
      }
    } else
      power <<= 1;
  }
  cout << cnt << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
