#include <bits/stdc++.h>
using namespace std;
long long n, m, j, i, k, b[1002], a[10000002];
string s, s0;
int main() {
  int t;
  cin >> t;
  for (int po = 1; po <= t; po++) {
    cin >> n >> m;
    for (i = 1; i <= 70; i++) b[i] = 0;
    long long sum = 0;
    for (i = 1; i <= m; i++) {
      cin >> a[i];
      sum += a[i];
    }
    if (sum < n)
      cout << "-1" << endl;
    else {
      sort(a + 1, a + m + 1);
      k = 1;
      while (2 * k <= n) k *= 2;
      j = 1;
      b[j] = k;
      long long v = n - k;
      while (v > 0) {
        while (v < k) k /= 2;
        b[++j] = k;
        v -= k;
      }
      reverse(b + 1, b + j + 1);
      v = 0;
      for (int u = 1; u <= j; u++) {
        for (i = 1; i <= m; i++) {
          if (b[u] == a[i]) {
            b[u] = 0;
            a[i] = 0;
            v++;
            break;
          }
          if (a[i] > b[u]) break;
        }
      }
      sort(b + 1, b + j + 1);
      reverse(b + 1, b + j + 1);
      sort(a + 1, a + m + 1);
      reverse(a + 1, a + m + 1);
      m -= v;
      j -= v;
      if (b[1] == 0)
        cout << "0" << endl;
      else {
        int x = 0;
        while (b[1] > 0) {
          if (b[j] <= a[m]) {
            while (b[j] != a[m]) {
              a[m] /= 2;
              m++;
              x++;
              a[m] = a[m - 1];
            }
            b[j] = 0;
            a[m] = 0;
            m--;
            j--;
          } else {
            while (a[m] < b[j]) {
              int p = m;
              while (a[p - 1] == a[p]) p--;
              while (p < m) {
                a[p] = 2 * a[m];
                a[m] = 0;
                m--;
                p++;
              }
              if (p == m) {
                a[m] = 0;
                m--;
              }
            }
            if (a[m] == b[j]) {
              b[j] = 0;
              j--;
              a[m] = 0;
              m--;
            }
          }
        }
        cout << x << endl;
      }
    }
  }
  return 0;
}
