#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = (1e9);
priority_queue<int> qt;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    while (!qt.empty()) qt.pop();
    long long n, m;
    scanf("%lld%lld", &n, &m);
    long long sum = 0;
    for (int i = 1; i <= m; i++) {
      int a;
      scanf("%d", &a);
      sum += a;
      qt.push(a);
    }
    int ans = -1;
    if (sum >= n) {
      ans = 0;
      while (n) {
        int now = qt.top();
        qt.pop();
        if (now <= n) {
          n -= now;
          sum -= now;
        } else {
          if (n <= sum - now) {
            sum -= now;
            continue;
          }
          qt.push(now / 2);
          qt.push(now / 2);
          ans++;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
