#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long add(long long a, long long b) {
  return ((a % MOD) + (b % MOD)) % MOD;
}
long long mul(long long a, long long b) {
  return ((a % MOD) * (b % MOD)) % MOD;
}
long long sub(long long a, long long b) {
  return ((a % MOD) - (b % MOD) + MOD) % MOD;
}
long long t, n, i, x, sum, temp, k, c, ans, cur;
vector<long long> v;
map<long long, long long> m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    sum = 0;
    m.clear();
    v.clear();
    for (i = 1; i <= k; i++) {
      cin >> x;
      sum += x;
      m[x]++;
    }
    if (sum < n) {
      cout << "-1\n";
      continue;
    }
    temp = n;
    c = 0;
    while (temp > 0) {
      v.push_back(temp % 2);
      temp /= 2;
      c++;
    }
    cur = 1;
    ans = 0;
    for (i = 0; i < c; i++) {
      if (v[i] == 0) {
        m[cur * 2] += m[cur] / 2;
        cur = cur * 2;
      } else {
        temp = cur;
        while (m[temp] == 0) {
          temp = temp * 2;
        }
        m[temp]--;
        while (temp != cur) {
          temp /= 2;
          m[temp]++;
          ans++;
        }
        m[temp]++;
        m[cur * 2] += (m[cur] - 1) / 2;
        cur = cur * 2;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
