#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> boxes;
vector<int> counts;
long long answer;
void In() {
  boxes.clear();
  counts.clear();
  answer = 0;
  cin >> n >> m;
  boxes.resize(m);
  counts.resize(63);
  for (int i = 0; i < m; i++) cin >> boxes[i];
}
long long Solve() {
  long long sum = 0;
  for (long long box : boxes) sum += box;
  if (sum < n) return -1;
  for (long long box : boxes) counts[log2(box)]++;
  for (int i = 0; i <= log2(n); i++)
    if ((1 << i) & n) {
      for (int j = 0; j < i; j++) {
        counts[j + 1] += counts[j] / 2;
        counts[j] %= 2;
      }
      if (!counts[i])
        for (int j = i + 1; j < 63; j++)
          if (counts[j]) {
            while (j != i) {
              counts[j]--;
              j--;
              counts[j] += 2;
              answer++;
            }
            break;
          }
      counts[i]--;
    }
  return answer;
}
void Out() { cout << answer << endl; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    In();
    answer = Solve();
    Out();
  }
}
