#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 100004;
long long T, m, cnt, p[70], i, sum, nearest, flag;
long long n, x, j, r;
long long read() {
  long long u = 0;
  char ch;
  ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') {
    u = (u << 3) + (u << 1) + ch - '0';
    ch = getchar();
  }
  return u;
}
int main() {
  cin >> T;
  while (T--) {
    memset(p, 0, sizeof(p));
    sum = 0;
    cnt = 0;
    cin >> n >> m;
    for (i = 1; i <= m; i++) {
      cin >> x;
      cnt = -1;
      sum += x;
      while (x) {
        x >>= 1;
        cnt++;
      }
      p[cnt]++;
    }
    if (sum < n) {
      cout << -1 << endl;
      continue;
    }
    cnt = 0;
    while (n) {
      if (n & 1) p[cnt]--;
      n >>= 1;
      cnt++;
    }
    sum = 0;
    for (i = 0; i <= 65; i++) {
      if (p[i] > 0)
        p[i + 1] += p[i] / 2, p[i] %= 2;
      else if (p[i] < 0) {
        for (j = i + 1; j <= 65; j++)
          if (p[j] > 0) {
            sum += j - i;
            p[j]--;
            for (r = j - 1; r >= i; r--) p[r]++;
            break;
          }
      }
    }
    cout << sum << endl;
  }
  return 0;
}
