#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
signed main() {
  int t;
  cin >> t;
  while (t--) {
    long long n;
    int m;
    cin >> n >> m;
    vector<int> pows(64);
    vector<int> number(64);
    long long sum = 0;
    for (int i = 0; i < m; i++) {
      int size;
      cin >> size;
      sum += size;
      for (int i = 0; i < 32; i++) {
        if ((1 << i) == size) {
          pows[i]++;
          break;
        }
      }
    }
    for (int i = 0; i < 64; i++)
      if ((1ll << i) & n) number[i] = 1;
    bool BAD = false;
    int answer_cnt = 0;
    for (int i = 0; i < pows.size() - 1; i++) {
      if (number[i] && pows[i])
        number[i] = 0, pows[i]--;
      else if (number[i]) {
        for (int j = i + 1; j < pows.size(); j++) {
          if (pows[j]) {
            answer_cnt += j - i;
            pows[j]--;
            number[i] = 0;
            break;
          }
          pows[j]++;
        }
        if (number[i] != 0) {
          BAD = true;
          break;
        }
      }
      if (pows[i] > 1) {
        pows[i + 1] += pows[i] / 2;
        pows[i] = pows[i] % 2;
      }
    }
    if (BAD) {
      cout << -1 << "\n";
    } else {
      cout << answer_cnt << "\n";
    }
  }
  return 0;
}
