#include <bits/stdc++.h>
using namespace std;
int a[100];
int main() {
  ios::sync_with_stdio(false);
  int t;
  unordered_map<int, int> mp;
  int tmp = 1;
  for (int i = 0; i <= 30; i++) {
    mp[tmp] = i;
    tmp *= 2;
  }
  cin >> t;
  while (t--) {
    long long v, n;
    long long sum = 0;
    cin >> v >> n;
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      sum += x;
      a[mp[x]]++;
    }
    if (sum < v) {
      cout << -1 << endl;
      continue;
    }
    int cur = 0;
    int ans = 0;
    while (v > 0) {
      if (v & 1) {
        if (a[cur] > 0) {
          a[cur]--;
        } else {
          for (int i = cur; i < 32; i++) {
            if (a[i] > 0) {
              for (int j = i; j > cur; j--) {
                a[j]--;
                a[j - 1] += 2;
                ans++;
              }
              break;
            }
          }
          a[cur]--;
        }
      }
      ++cur;
      a[cur] += a[cur - 1] / 2;
      a[cur - 1] = a[cur - 1] % 2;
      v = v >> 1;
    }
    cout << ans << endl;
  }
  return 0;
}
