#include <bits/stdc++.h>
using namespace std;
template <typename T>
void pr(vector<T> &v) {
  for (int i = 0; i < (int)(v).size(); i++) cout << v[i] << " ";
  cout << '\n';
  ;
}
template <typename T>
void pr(vector<vector<T>> &v) {
  for (int i = 0; i < (int)(v).size(); i++) {
    pr(v[i]);
  }
}
template <typename T>
void re(T &x) {
  cin >> x;
}
template <typename T>
void re(vector<T> &a) {
  for (int i = 0; i < (int)(a).size(); i++) re(a[i]);
}
template <class Arg, class... Args>
void re(Arg &first, Args &...rest) {
  re(first);
  re(rest...);
}
template <typename T>
void pr(T x) {
  cout << x << '\n';
  ;
}
template <class Arg, class... Args>
void pr(const Arg &first, const Args &...rest) {
  cout << first << " ";
  pr(rest...);
  cout << '\n';
  ;
}
void ps() {
  cout << '\n';
  ;
}
template <class T, class... Ts>
void ps(const T &t, const Ts &...ts) {
  cout << t;
  if (sizeof...(ts)) cout << " ";
  ps(ts...);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tcases;
  cin >> tcases;
  for (int tcase = 1; tcase < tcases + 1; tcase++) {
    long long n, m;
    cin >> n >> m;
    vector<long long> a(m);
    re(a);
    priority_queue<long long, vector<long long>, greater<long long>> pq;
    for (int i = 0; i < m; i++) {
      pq.push(a[i]);
    }
    long long ans = 0;
    while (n > 0 && !pq.empty()) {
      if (n % 2 == 1) {
        while (pq.top() != 1) {
          int x = pq.top();
          pq.pop();
          x /= 2;
          pq.push(x);
          pq.push(x);
          ans++;
        }
        pq.pop();
        n -= 1;
      }
      int num = 0;
      while (!pq.empty() && pq.top() == 1) {
        num++;
        pq.pop();
      }
      vector<long long> temp;
      while (!pq.empty()) {
        temp.push_back(pq.top() / 2);
        pq.pop();
      }
      for (int i = 0; i < (int)(temp).size(); i++) {
        pq.push(temp[i]);
      }
      for (int i = 0; i < num / 2; i++) {
        pq.push(1);
      }
      n /= 2;
    }
    if (n != 0 && pq.empty()) {
      pr(-1);
    } else {
      pr(ans);
    }
  }
}
