#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int mex = 10000000;
int vis[26] = {0};
vector<int> outp;
vector<int> v[26];
void dfs(int n) {
  outp.push_back(n);
  vis[n] = 1;
  for (int i = 0; i < v[n].size(); i++)
    if (vis[v[n][i]] == 0) dfs(v[n][i]);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    long long int arr[m];
    map<long long int, int> mp;
    for (int i = 0; i < m; i++) {
      cin >> arr[i];
      mp[arr[i]]++;
    }
    int ans = 0, flg = 0;
    for (int i = 0; i < 64; i++) {
      long long int y = (1ll << i);
      if (n & y) {
        if (mp[y] > 0)
          mp[y]--;
        else {
          int fg = 0;
          long long int y1 = 0;
          for (int j = i + 1; j < 64; j++) {
            y1 = (1ll << j);
            if (mp[y1] > 0) {
              mp[y1]--;
              for (int k = i + 1; k < j; k++) {
                long long int u1 = (1ll << k);
                mp[u1]++;
              }
              ans += (j - i);
              fg = 1;
              break;
            }
          }
          if (fg == 0) {
            flg = 1;
          }
        }
      }
      if (i != 63) mp[2 * y] += (mp[y] / 2);
    }
    if (flg == 1)
      cout << "-1" << endl;
    else
      cout << ans << endl;
  }
}
