#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t) {
    t--;
    long long int n, k;
    cin >> n >> k;
    long long int a[k];
    map<long long int, long long int> m;
    for (int i = 0; i < k; ++i) {
      cin >> a[i];
      m[a[i]]++;
    }
    long long int pow = 1, f = 0, ans = 0;
    while (n) {
      if (n % 2 == 1) {
        if (m[pow] == 0) {
          long long int x = 0;
          for (long long int i = pow; i < 1000000000; i *= 2) {
            if (m[i] != 0) {
              x = i;
              break;
            }
          }
          m[x]--;
          while (x != pow && x != 0) {
            x /= 2;
            m[x] += 1;
            ans += 1;
          }
          if (x == 0) {
            f = 1;
            break;
          }
        } else {
          m[pow]--;
        }
      }
      m[2 * pow] += m[pow] / (2);
      m[pow] = 0;
      n /= 2;
      pow *= 2;
    }
    if (f) {
      cout << -1 << "\n";
    } else {
      cout << ans << "\n";
    }
  }
  return 0;
}
