#include <bits/stdc++.h>
using namespace std;
long long T, n, m, ans;
long long a[100100];
long long now[700];
long long n2[700];
long long need[700];
int main() {
  n2[0] = 1;
  for (int i = 1; i <= 65; i++) {
    n2[i] = n2[i - 1] * 2;
  }
  cin >> T;
  while (T--) {
    memset(now, 0, sizeof now);
    memset(a, 0, sizeof a);
    memset(need, 0, sizeof need);
    ans = 0;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) scanf("%lld", &a[i]);
    long long su = 0;
    for (int i = 1; i <= m; i++) su += a[i];
    if (su < n) {
      puts("-1");
      continue;
    }
    for (int i = 1; i <= m; i++) {
      for (int j = 0; j <= 65; j++) {
        if (a[i] == n2[j]) {
          now[j]++;
          break;
        }
      }
    }
    int nowp = 0;
    while (n) {
      need[nowp] = n % 2;
      n >>= 1;
      nowp++;
    }
    int ans = 0;
    for (int i = 0; i <= nowp; i++) {
      if (need[i]) {
        for (int j = i; j <= 65; j++) {
          if (now[j]) {
            now[j]--;
            ans += j - i;
            now[i] += n2[j - i];
            now[i]--;
            break;
          }
        }
      }
      now[i + 1] += now[i] / 2;
      now[i] %= 2;
    }
    printf("%d\n", ans);
  }
}
