#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long sum = 0;
    long long bit[70] = {0};
    for (int i = 0; i < m; i++) {
      long long x;
      cin >> x;
      long long fk = log2(x);
      bit[fk] += 1;
      sum += x;
    }
    if (sum < n) {
      cout << "-1\n";
      continue;
    }
    long long i = 0, cnt = 0;
    while (i < 54) {
      if ((n >> i) & 1 != 0) {
        if (bit[i] > 0) {
          bit[i] -= 1;
        } else {
          while (i < 54 && bit[i] == 0) {
            i++;
            cnt++;
          }
          bit[i] -= 1;
          continue;
        }
      }
      bit[i + 1] += bit[i] / 2;
      i++;
    }
    cout << cnt << "\n";
  }
}
