#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e19;
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y % 2 == 1) res = (res * x);
    x = (x * x);
    y = y / 2;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  vector<int> v[100001];
  int t;
  cin >> t;
  while (t--) {
    long long n, m, i, j, a, b, c, k = 0, r, s = 0, p, x, y, f = 0;
    cin >> n >> m;
    unordered_map<long long, long long> mp;
    for (i = 0; i < m; i++) {
      cin >> c;
      mp[c]++;
    }
    c = n, i = 0;
    while (c > 0) {
      p = c % 2;
      c = c / 2;
      if (p == 0) {
        i++;
        continue;
      }
      a = power(2, i);
      i++;
      r = a;
      y = 0;
      for (j = 0; j < i; j++) y = y + mp[power(2, j)] * power(2, j);
      if (y >= a) {
        while (r > 0) {
          b = a / r;
          x = min(mp[r], b);
          a = a - x * r;
          mp[r] -= x;
          if (a == 0) break;
          r = r / 2;
        }
      } else {
        r = 2 * r;
        while (r <= 1e9) {
          if (mp[r]) {
            mp[r]--;
            r /= 2;
            s++;
            while (r >= a) {
              mp[r]++;
              if (r == a) break;
              r = r / 2;
              s++;
            }
            a = 0;
            break;
          }
          r = r * 2;
        }
      }
      if (a != 0) {
        f = 1;
        break;
      }
    }
    if (f == 1)
      cout << -1 << '\n';
    else
      cout << s << '\n';
  }
}
