#include <bits/stdc++.h>
#define LL long long
#define pb push_back
using namespace std;
map<LL,LL> W;
int t, m;
LL n;
int main(){
	scanf("%d", &t);
	while(t--){
		W.clear();
		scanf("%lld %d", &n, &m);
		LL sum = 0LL;
		for(int i = 0; i < m; i++){
			LL x;
			scanf("%lld", &x);
			W[x]++;
			sum += x;
		}
		if(sum < n){
			printf("-1\n");
			continue;
		}
		LL ans = 0LL;
		for(LL i = 1; i <= n; i <<= 1LL){
			if(!(n & i)) W[i<<1LL] += (W[i]>>1LL);
			else if(W[i]){
				W[i]--;
				W[i<<1LL] += (W[i]>>1LL);
			}else{
				for(LL j = 2*i; ; j <<= 1LL){
					if(W[j]){
						W[j]--;
						while(j > i){
							ans++;
							W[j>>=1LL]++;
						}
						break;
					}
				}
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
#define VI vector<int>
#define pii pair<int,int>
using namespace std;
LL n; int m;
int A[100010];
map<LL,LL> W;
void upd(LL t){
	for(LL k = 2; k <= t; k <<= 1LL){
		W[k] += W[k>>1]/2;
		W[k>>1] &= 1;
	}
}
int main(){
	int t;
	scanf("%d", &t);
	while(t--){
		W.clear();
		scanf("%lld %d", &n, &m);
		LL sum = 0;
		for(int i = 0; i < m; i++) scanf("%d", &A[i]), sum += A[i];
		if(sum < n){
			printf("-1\n");
			continue;
		}
		sort(A, A + m);
		int j = 0;
		LL ans = 0;
		for(LL i = 0; i < 62; i++){
			if(!(n & (1LL<<i))) continue;
			while(true){
				upd(1LL<<i);
				if(W[1LL<<i]) break;
				if(A[j] <= (1LL<<i)){
					W[A[j++]]++;
				}else{
					LL d = 1;
					while(A[j] > (1LL<<i)){
						d <<= 1;
						A[j] >>= 1;
						ans++;
					}
					W[A[j++]] += d-1;
					break;
				}
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
using namespace std;
map<LL,LL> W;
int t, m;
LL n;
int main(){
	scanf("%d", &t);
	while(t--){
		scanf("%lld %d", &n, &m);
		LL sum = 0LL;
		for(int i = 0; i < m; i++){
			LL x;
			scanf("%lld", &x);
			W[x]++;
			sum += x;
		}
		if(sum < n){
			printf("-1\n");
			continue;
		}
		LL ans = 0LL;
		for(LL i = 1; i <= n; i <<= 1LL){
			if(!(n & i)) W[i<<1LL] += (W[i]>>1LL);
			else if(W[i]){
				W[i]--;
				W[i<<1LL] += (W[i]>>1LL);
			}else{
				for(LL j = 2*i; ; j <<= 1LL){
					if(W[j]){
						W[j]--;
						while(j > i){
							ans++;
							W[j>>=1LL]++;
						}
						break;
					}
				}
			}
		}
		printf("%lld\n", ans);
		W.clear();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second

const int N=5e5+10, L = 64 ;
ll n, m,t, x, S;
int bit[L + 10] ;

int main()
{
#ifdef Mohammad
    freopen("input.in","r",stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while(t--)
    {
        cin >> n >> m ;
        bool f = 0 ;
        int Ans = 0 ;
        S = 0;
        for (int i = 0 ; i<=L ; i++)
            bit[i] = 0 ;

        for (int i = 1 ; i<= m ; i++)
        {
            cin >> x ;
            int e = log2(x);
            if (n & x)
                n -= x ;
            else
                bit[e]++ ;
            S += x ;
        }

        if (S < n)
        {
            cout<<"-1\n";
            continue ;
        }
        for (int b = 0 ; n && b < L ; b++)
        {
            if ( (n & (1 << b )) == 0 )
                bit[b+1] += bit[b] / 2 ;

            else if (n & (1 << b))
            {
                if (bit[b])
                {
                    bit[b] -- ;
                    n -= 1<<b ;
                    bit[b+1] += bit[b] / 2 ;
                }
                else
                {
                    int j = b ;
                    for( j = b ; j<=L ; j++)
                        if (bit[j])
                            break;
                    if (j > L || j == b)
                    {
                        f = 1 ;
                        break ;
                    }
                    bit[j]-- ;
                    while(j > b)
                    {
                        Ans++ ;
                        j--;
                        bit[j]++ ;
                        if (j == b)
                            n -= 1<<b ;
                    }
                }
            }
        }
        if (f)
            cout<<"-1\n";
        else
            cout<<Ans<<"\n" ;

    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second

const int N=5e5+10, L = 31 ;
int n, m,t, x ;
int bit[33] ;

int main()
{
#ifdef Mohammad
    freopen("input.in","r",stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while(t--)
    {
        cin >> n >> m ;
        bool f = 0 ;
        int Ans = 0 ;
        for (int i = 0 ; i<=L ; i++)
            bit[i] = 0 ;

        for (int i = 1 ; i<= m ; i++)
        {
            cin >> x ;
            int e = log2(x);
            if (n & x)
                n -= x ;
            else
                bit[e]++ ;
        }

        for (int bitt = 0 ; n && bitt < L ; bitt++)
        {
            if ( (n & (1 << bitt )) == 0 && bit [bitt] )
                bit[bitt +1 ] += bit[bitt] / 2 ;

            else if (n & (1 << bitt))
            {
                // cout<<bitt<< " " << bit[bitt]<<"\n";
                if (bit[bitt])
                {
                    bit[bitt] -- ;
                    n -= 1<<bitt ;
                    bit[bitt+1] += bit[bitt] / 2 ;
                }
                else
                {
                    int j = bitt ;
                    for( j = bitt ; j<=L ; j++)
                        if (bit[j])
                            break;
                    if (j > L || j == bitt)
                    {
                        f = 1 ;
                        break ;
                    }
                    bit[j]-- ;
//cout<<bitt<<" "<<j<<"\n";
                    while(j > bitt)
                    {
                        Ans++ ;
                        j--;
                        bit[j]++ ;
                        if (j == bitt)
                            n -= 1<<bitt ;

                    }
                }
            }
        }
        if (f)
            cout<<"-1\n";
        else
            cout<<Ans<<"\n" ;

    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second

const int N=5e5+10 ;
int a[N], n;
ll need, L, Ans = 0 ;

int main()
{
#ifdef Mohammad
    freopen("input.in","r",stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t ;
    cin >> t ;
    while(t--)
    {
        cin >> need >> n ;
        L = Ans = 0 ;
        for (int i = 1 ; i<=n; i++)
            cin >> a[i];

        sort(a+1, a+1+n);

        for (int i = n ; i>= 1 ; i--)
            if (a[i] <= need)
                need -= a[i],a[i] = 0 ;

        if (need)
        {
            for (int i = 1 ; i<=n; i++)
                if (a[i] >= need)
                {
                    L = i ;
                    break;
                }

            if (L)
            {

                L = a[L] /2;
                Ans++;
                while( L && need)
                {
                    if (L <= need)
                        need -= L;
                    if (!need)
                        break;
                    Ans ++ ;
                    L /= 2 ;

                }
            }
                else
                    Ans = -1 ;
        }
        cout<<Ans<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second

const int N=5e5+10, L = 60 ;
ll n, m,t, x, S;
int bit[L + 10] ;

int main()
{
#ifdef Mohammad
    freopen("input.in","r",stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while(t--)
    {
        cin >> n >> m ;
        bool f = 0 ;
        int Ans = 0 ;
        S = 0;
        for (int i = 0 ; i<=L ; i++)
            bit[i] = 0 ;

        for (int i = 1 ; i<= m ; i++)
        {
            cin >> x ;
            int e = log2(x);
            if (n & x)
                n -= x ;
            else
                bit[e]++ ;
            S += x ;
        }

        if (S < n)
        {
            cout<<"-1\n";
            continue ;
        }
        for (int b = 0 ; n && b < L ; b++)
        {
            if ( (n & (1ll << b )) == 0 )
                bit[b+1] += bit[b] / 2 ;

            else if (n & (1ll << b))
            {
                if (bit[b])
                {
                    bit[b] -- ;
                    n -= 1ll<<b ;
                    bit[b+1] += bit[b] / 2 ;
                }
                else
                {
                    int j = b ;
                    for( j = b ; j<=L ; j++)
                        if (bit[j])
                            break;
                    if (j > L || j == b)
                    {
                        f = 1 ;
                        break ;
                    }
                    bit[j]-- ;
                    while(j > b)
                    {
                        Ans++ ;
                        j--;
                        bit[j]++ ;
                        if (j == b)
                            n -= 1<<b ;
                    }
                }
            }
        }
        if (f)
            cout<<"-1\n";
        else
            cout<<Ans<<"\n" ;

    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second

const int N=5e5+10, L = 60 ;
ll n, m,t, x, S;
int bit[L + 10] ;

int main()
{
#ifdef Mohammad
    freopen("input.in","r",stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while(t--)
    {
        cin >> n >> m ;
        bool f = 0 ;
        int Ans = 0 ;
        S = 0;
        for (int i = 0 ; i<=L ; i++)
            bit[i] = 0 ;

        for (int i = 1 ; i<= m ; i++)
        {
            cin >> x ;
            int e = log2(x);
            if (n & x)
                n -= x ;
            else
                bit[e]++ ;
            S += x ;
        }

        if (S < n)
        {
            cout<<"-1\n";
            continue ;
        }
        for (int b = 0 ; n && b < L ; b++)
        {
            if ( (n & (1ll << b )) == 0 )
                bit[b+1] += bit[b] / 2 ;

            else if (n & (1ll << b))
            {
                if (bit[b])
                {
                    bit[b] -- ;
                    n -= 1ll<<b ;
                    bit[b+1] += bit[b] / 2 ;
                }
                else
                {
                    int j = b ;
                    for( j = b ; j<=L ; j++)
                        if (bit[j])
                            break;

                    bit[j]-- ;
                    while(j > b)
                    {
                        Ans++ ;
                        j--;
                        bit[j]++ ;
                        if (j == b)
                            n -= 1<<b ;
                    }
                }
            }
        }
            cout<<Ans<<"\n" ;

    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second

const int N=5e5+10 ;
int a[N], n;
ll need, L, Ans = 0 , one ;

int main()
{
#ifdef Mohammad
    freopen("input.in","r",stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t ;
    cin >> t ;
    while(t--)
    {
        cin >> need >> n ;
        L = Ans = 0 , one = 0 ;
        for (int i = 1 ; i<=n; i++)
            {
                cin >> a[i];
                if (a[i] == 1)
                    one = 1;
            }

        sort(a+1, a+1+n);

        for (int i = n ; i>= 1 ; i--)
            if (a[i] <= need)
                need -= a[i],a[i] = 0 ;

        if (need)
        {
         if ((need & 1) && one )
                    need ++ ;
            for (int i = 1 ; i<=n; i++)
                if (a[i] >= need)
                {
                    L = i ;
                    break;
                }

            if (L)
            {

                L = a[L] /2;
                Ans++;
                while( L && need)
                {
                    if (L <= need)
                        need -= L;
                    if (!need)
                        break;
                    Ans ++ ;
                    L /= 2 ;

                }
            }
                else
                    Ans = -1 ;
        }
        cout<<Ans<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second

const int N=5e5+10, L = 31 ;
ll n, m,t, x ;
int bit[33] ;

int main()
{
#ifdef Mohammad
    freopen("input.in","r",stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while(t--)
    {
        cin >> n >> m ;
        bool f = 0 ;
        int Ans = 0 ;
        for (int i = 0 ; i<=L ; i++)
            bit[i] = 0 ;

        for (int i = 1 ; i<= m ; i++)
        {
            cin >> x ;
            int e = log2(x);
            if (n & x)
                n -= x ;
            else
                bit[e]++ ;
        }

        for (int b = 0 ; n && b < L ; b++)
        {
            if ( (n & (1 << b )) == 0 )
                bit[b+1] += bit[b] / 2 ;

            else if (n & (1 << b))
            {
                if (bit[b])
                {
                    bit[b] -- ;
                    n -= 1<<b ;
                    bit[b+1] += bit[b] / 2 ;
                }
                else
                {
                    int j = b ;
                    for( j = b ; j<=L ; j++)
                        if (bit[j])
                            break;
                    if (j > L || j == b)
                    {
                        f = 1 ;
                        break ;
                    }
                    bit[j]-- ;
                    while(j > b)
                    {
                        Ans++ ;
                        j--;
                        bit[j]++ ;
                        if (j == b)
                            n -= 1<<b ;
                    }
                }
            }
        }
        if (f)
            cout<<"-1\n";
        else
            cout<<Ans<<"\n" ;

    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second

const int N=5e5+10 ;
int n, m,t, x ;
int bit[33] ;

int main()
{
#ifdef Mohammad
    freopen("input.in","r",stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while(t--)
    {
        cin >> n >> m ;
        bool f = 0 ;
        int Ans = 0 ;
        for (int i = 0 ; i<= 31 ; i++)
            bit[i] = 0 ;

        for (int i = 1 ; i<= m ; i++)
        {
            cin >> x ;
            int e = log2(x);
            if (n & x)
                n -= x ;
            else
                bit[e]++ ;
        }

        for (int bitt = 0 ; n && bitt < 30 ; bitt++)
        {
            if ( (n & (1 << bitt )) == 0 && bit [bitt] )
                bit[bitt +1 ] += bit[bitt] / 2 ;

            else if (n & (1 << bitt))
            {
                // cout<<bitt<< " " << bit[bitt]<<"\n";
                if (bit[bitt])
                {
                    bit[bitt] -- ;
                    n -= 1<<bitt ;
                    bit[bitt+1] += bit[bitt] / 2 ;
                }
                else
                {
                    int j = bitt ;
                    for( j = bitt ; j<=30 ; j++)
                        if (bit[j])
                            break;
                    if (j > 30)
                    {
                        f = 1 ;
                        break ;
                    }
                    bit[j]-- ;
//cout<<bitt<<" "<<j<<"\n";
                    while(j > bitt)
                    {
                        Ans++ ;
                        j--;
                        bit[j]++ ;
                        if (j == bitt)
                            n -= 1<<bitt ;

                    }
                }
            }
        }
        if (f)
            cout<<"-1\n";
        else
            cout<<Ans<<"\n" ;

    }
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
       ll n,k,p=0;
       cin>>n>>k;
       ll a,s,ans=0,sum=0,j;
       map<ll,ll> m;
       for(ll i=0;i<k;i++)
       {
           cin>>a;
           sum+=a;
           for(ll i=0;i<=80;i++)
           {
               if((1LL<<i)&a)
               {
                   m[i]++;
                   break;
               }
           }
       }
       if(sum<n)
        cout<< "-1"<< "\n";
       else
       {
            for(ll i=0;(1LL<<i)<=n;i++)
            {
                if((1LL<<i)&n)
                {
                    if(m[i])
                    {
                        m[i]--;
                        m[i+1]+=m[i]/2;
                    }
                    else
                    {
                        j=i;
                        while(m[j]==0)
                        {
                            ans++;
                            m[j]++;
                            j++;
                            //cout<<j<< "\n";
                        }
                        m[j]--;
                    }
                }
                else
                {
                    m[i+1]+=m[i]/2;
                }
            }
            cout<<ans<< "\n";
       }

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
       ll n,m,p=0;
       cin>>n>>m;
       ll a,s,ans=0,sum=0,j;
       ll v[100]={0};
       for(ll i=0;i<m;i++)
       {
           cin>>a;
           sum+=a;
           v[(ll)log2(a)]++;
       }
       if(sum<n)
        cout<< "-1"<< "\n";
       else
       {
             for(ll i=0;i<=(ll)log2(n);i++)
             {
                 if((1LL<<i)&n)
                 {
                     if(v[i]>0)
                     {
                         v[i]--;
                         p+=(1LL<<v[i]);
                     }

                    else
                     {
                         if(p>=(1LL<<i))
                         {
                             p-=(1LL<<i);
                             continue;
                         }
                         j=i+1;
                         //cout<<v[j]<< "\n";
                         s=1;
                         while(v[j]==0)
                         {
                            j++;
                            s++;
                         }
                         //cout<<s<< "\n";
                         ans+=s;
                         //cout<<ans<< "\n";
                         v[i]+=((1LL<<s)-1);
                         p+=((1LL<<i)*v[i]);
                         v[j]--;
                         //p+=(v[j])
                     }

                 }
                 else
                 {
                     //cout<<i<< " "<<v[i]<< "\n";
                     if(v[i]>0)
                     {
                         p+=((1LL<<i)*v[i]);
                         //cout<<p<< "\n";
                     }
                 }
             }
             cout<<ans<< "\n";
       }

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
       ll n,m,p=0,mx=INT_MIN;
       cin>>n>>m;
       ll a,s,ans=0,sum=0,j;
       map<ll,ll> v;
       for(ll i=0;i<m;i++)
       {
           cin>>a;
           sum+=a;
           if(a>mx)
            mx=a;
           v[(ll)log2(a)]++;
       }
       if(sum<n)
        cout<< "-1"<< "\n";
       else
       {
           ll r=(ll)log2(mx);
             for(ll i=0;i<=(ll)log2(n);i++)
             {
                 if((1LL<<i)&n)
                 {
                     if(v[i]>0)
                     {
                         v[i]--;
                     }
                     else
                     {
                         if(p>=(1LL<<i))
                         {
                             p-=(1LL<<i);
                             continue;
                         }
                         j=i+1;
                         //cout<<v[j]<< "\n";
                         s=1;
                         while(v[j]==0)
                         {
                            j++;
                            s++;
                         }
                         //cout<<s<< "\n";
                         ans+=s;
                         v[j]--;
                     }
                 }
                 else
                 {
                     if(v[i]>0)
                     {
                         p+=((1LL<<i)*v[i]);
                     }
                 }
             }
             cout<<ans<< "\n";
       }
        v.clear();
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
       ll n,m,p=0;
       cin>>n>>m;
       ll a,s,ans=0,sum=0,j;
       int v[100000]={0};
       for(ll i=0;i<m;i++)
       {
           cin>>a;
           sum+=a;
           v[(ll)log2(a)]++;
       }
       if(sum<n)
        cout<< "-1"<< "\n";
       else
       {
             for(ll i=0;i<=(ll)log2(n);i++)
             {
                 if((1LL<<i)&n)
                 {
                     if(v[i]>0)
                     {
                         v[i]--;
                         p+=(1LL<<v[i]);
                     }

                    else
                     {
                         if(p>=(1LL<<i))
                         {
                             p-=(1LL<<i);
                             continue;
                         }
                         j=i+1;
                         //cout<<v[j]<< "\n";
                         s=1;
                         while(v[j]==0)
                         {
                            j++;
                            s++;
                         }
                         //cout<<s<< "\n";
                         ans+=s;
                         //cout<<ans<< "\n";
                         v[i]+=((1LL<<s)-1);
                         p+=((1LL<<i)*v[i]);
                         v[j]--;
                         //p+=(v[j])
                     }

                 }
                 else
                 {
                     //cout<<i<< " "<<v[i]<< "\n";
                     if(v[i]>0)
                     {
                         p+=((1LL<<i)*v[i]);
                         //cout<<p<< "\n";
                     }
                 }
             }
             cout<<ans<< "\n";
       }

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
       ll n,m,p=0;
       cin>>n>>m;
       ll a,s,ans=0,sum=0,j;
       int v[100]={0};
       for(ll i=0;i<m;i++)
       {
           cin>>a;
           sum+=a;
           v[(ll)log2(a)]++;
       }
       if(sum<n)
        cout<< "-1"<< "\n";
       else
       {
             for(ll i=0;i<=(ll)log2(n);i++)
             {
                 if((1LL<<i)&n)
                 {
                     if(v[i]>0)
                     {
                         v[i]--;
                         p+=(1LL<<v[i]);
                     }

                    else
                     {
                         if(p>=(1LL<<i))
                         {
                             p-=(1LL<<i);
                             continue;
                         }
                         j=i+1;
                         //cout<<v[j]<< "\n";
                         s=1;
                         while(v[j]==0)
                         {
                            j++;
                            s++;
                         }
                         //cout<<s<< "\n";
                         ans+=s;
                         //cout<<ans<< "\n";
                         v[i]=((1LL<<s)-1);
                         p+=(1LL<<v[i]);
                         v[j]--;
                         //p+=(v[j])
                     }

                 }
                 else
                 {
                     //cout<<i<< " "<<v[i]<< "\n";
                     if(v[i]>0)
                     {
                         p+=((1LL<<i)*v[i]);
                         //cout<<p<< "\n";
                     }
                 }
             }
             cout<<ans<< "\n";
       }

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
       ll n,m,p=0,mx=INT_MIN;
       cin>>n>>m;
       ll a[m],s,ans=0,f=1,sum=0,j;
       map<ll,ll> v;
       for(ll i=0;i<m;i++)
       {
           cin>>a[i];
           sum+=a[i];
           if(a[i]>mx)
            mx=a[i];
           v[(ll)log2(a[i])]++;
       }
       if(sum<n)
        cout<< "-1"<< "\n";
       else
       {
           ll r=(ll)log2(mx);
             for(ll i=0;i<=(ll)log2(n);i++)
             {
                 if((1LL<<i)&n)
                 {
                     if(v[i]>0)
                     {
                         v[i]--;
                     }
                     else
                     {
                         if(p>=(1LL<<i))
                         {
                             p-=(1LL<<i);
                             continue;
                         }
                         j=i+1;
                         //cout<<v[j]<< "\n";
                         s=1;
                         while(v[j]==0)
                         {
                            j++;
                            s++;
                         }
                         //cout<<s<< "\n";
                         ans+=s;
                         v[j]--;
                     }
                 }
                 else
                 {
                     if(v[i]>0)
                     {
                         p+=((1LL<<i)*v[i]);
                     }
                 }
             }
             cout<<ans<< "\n";
             v.clear();
       }

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
       ll n,m,p=0,mx=INT_MIN;
       cin>>n>>m;
       ll a[m],s,ans=0,f=1,sum=0,j;
       map<ll,ll> v;
       for(ll i=0;i<m;i++)
       {
           cin>>a[i];
           sum+=a[i];
           if(a[i]>mx)
            mx=a[i];
           v[(ll)log2(a[i])]++;
       }
       if(sum<n)
        cout<< "-1"<< "\n";
       else
       {
           ll r=(ll)log2(mx);
             for(ll i=0;i<=(ll)log2(n);i++)
             {
                 if((1LL<<i)&n)
                 {
                     if(v[i]>0)
                     {
                         v[i]--;
                     }
                     else
                     {
                         if(p>=(1LL<<i))
                         {
                             p-=(1LL<<i);
                             continue;
                         }
                         j=i+1;
                         //cout<<v[j]<< "\n";
                         s=1;
                         while(v[j]==0)
                         {
                            j++;
                            s++;
                         }
                         //cout<<s<< "\n";
                         ans+=s;
                         v[j]--;
                     }
                 }
                 else
                 {
                     if(v[i]>0)
                     {
                         p+=((1LL<<i)*v[i]);
                     }
                 }
             }
             cout<<ans<< "\n";
       }

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
       ll n,m,p=0;
       cin>>n>>m;
       ll a,s,ans=0,sum=0,j;
       int v[100]={0};
       for(ll i=0;i<m;i++)
       {
           cin>>a;
           sum+=a;
           v[(ll)log2(a)]++;
       }
       if(sum<n)
        cout<< "-1"<< "\n";
       else
       {
             for(ll i=0;i<=(ll)log2(n);i++)
             {
                 if((1LL<<i)&n)
                 {
                     if(v[i]>0)
                     {
                         v[i]--;
                         p+=(1LL<<v[i]);
                     }

                    else
                     {
                         if(p>=(1LL<<i))
                         {
                             p-=(1LL<<i);
                             continue;
                         }
                         j=i+1;
                         //cout<<v[j]<< "\n";
                         s=1;
                         while(v[j]==0)
                         {
                            j++;
                            s++;
                         }
                         //cout<<s<< "\n";
                         ans+=s;
                         //cout<<ans<< "\n";
                         v[j]--;
                         //p+=(v[j])
                     }
                 }
                 else
                 {
                     //cout<<i<< " "<<v[i]<< "\n";
                     if(v[i]>0)
                     {
                         p+=((1LL<<i)*v[i]);
                         //cout<<p<< "\n";
                     }
                 }
             }
             cout<<ans<< "\n";
       }

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
       ll n,m,p=0;
       cin>>n>>m;
       ll a,s,ans=0,sum=0,j;
       int v[100]={0};
       for(ll i=0;i<m;i++)
       {
           cin>>a;
           sum+=a;
           v[(ll)log2(a)]++;
       }
       if(sum<n)
        cout<< "-1"<< "\n";
       else
       {
             for(ll i=0;i<=(ll)log2(n);i++)
             {
                 if((1LL<<i)&n)
                 {
                     if(v[i]>0)
                     {
                         v[i]--;
                     }
                     else
                     {
                         if(p>=(1LL<<i))
                         {
                             p-=(1LL<<i);
                             continue;
                         }
                         j=i+1;
                         //cout<<v[j]<< "\n";
                         s=1;
                         while(v[j]==0)
                         {
                            j++;
                            s++;
                         }
                         //cout<<s<< "\n";
                         ans+=s;
                         v[j]--;
                     }
                 }
                 else
                 {
                     if(v[i]>0)
                     {
                         p+=((1LL<<i)*v[i]);
                     }
                 }
             }
             cout<<ans<< "\n";
       }

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
       ll n,m,p=0;
       cin>>n>>m;
       ll a,s,ans=0,sum=0,j;
       int v[100]={0};
       for(ll i=0;i<m;i++)
       {
           cin>>a;
           sum+=a;
           v[(ll)log2(a)]++;
       }
       if(sum<n)
        cout<< "-1"<< "\n";
       else
       {
             for(ll i=0;i<=(ll)log2(n);i++)
             {
                 if((1LL<<i)&n)
                 {
                     if(v[i]>0)
                     {
                         v[i]--;
                         p+=(1LL<<v[i]);
                     }

                    else
                     {
                         if(p>=(1LL<<i))
                         {
                             p-=(1LL<<i);
                             continue;
                         }
                         j=i+1;
                         //cout<<v[j]<< "\n";
                         s=1;
                         while(v[j]==0)
                         {
                            j++;
                            s++;
                         }
                         //cout<<s<< "\n";
                         ans+=s;
                         //cout<<ans<< "\n";
                         v[i]+=((1LL<<s)-1);
                         p+=((1LL<<i)*v[i]);
                         v[j]--;
                         //p+=(v[j])
                     }

                 }
                 else
                 {
                     //cout<<i<< " "<<v[i]<< "\n";
                     if(v[i]>0)
                     {
                         p+=((1LL<<i)*v[i]);
                         //cout<<p<< "\n";
                     }
                 }
             }
             cout<<ans<< "\n";
       }

    }
    return 0;
}


//#pragma comment(linker, "/stack:200000000")
#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define ULL unsigned long long
const LL INF=1LL<<60;
const double PI = acos(-1.0);

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

//// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//cout<<*X.find_by_order(1)<<endl;
//cout<<X.order_of_key(-5)<<endl;

//typedef tree<
//pll,
//null_type,
//less< pll >,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define mem(x,y) 	memset(x,y,sizeof x )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
#define lc			tree[idx*2]
#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
LL X[4]={0,0,-1,1};
LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));} // check bit
inline int setBit(int N,int pos){	return N=N | (1<<pos);}// set bit
inline int unsetBit(int N,int pos){	return N=( N & ( ~( 1<<pos ) ) );}// unset bit
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }// toggle bit

LL modMul(LL a, LL b,LL mod){

    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}

LL powerMod(LL a,LL b,LL mod){
	if(b==0)return 1LL%mod;
	LL x=powerMod(a,b/2,mod);
	x = (x%mod*x%mod)%mod;
	if(b%2==1)x = (x%mod*a%mod)%mod;
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
const int mx = 2e5+7;

LL arr[mx];

int main(){

//    BOOST;
//    READ;
//    WRITE;
    int t;

    cin>>t;
    while(t--){

        LL n,m;
        priority_queue<LL> q;
        cin>>n>>m;
        LL sum = 0;
        for(int i=1;i<=m;i++){
            LL d;cin>>d;
            q.push(d);
            arr[i] = d;
            sum += d;
        }

        if(sum < n){
            cout<<-1<<endl;
            continue;
        }

        multiset<LL> st;
        LL tomake = n;
        while(!q.empty()){
            LL x = q.top();
            if(x<=tomake)tomake -= x;
            else st.insert(x);
            q.pop();
        }
        int div = 0;

//        cout<<tomake<<endl;
        while(tomake>0){

            if(st.empty()){
                div = -1;
                break;
            }

            auto xx = st.lower_bound(tomake);
            LL x = *xx;
//            cout<<x<<endl;
            while(x>0){
//                cout<<tomake<<" "<<x<<" "<<div<<endl;
                if( tomake==0 )break;
                if(tomake >= x){
                    tomake -= x;
                }
                if(tomake==0)break;
                x/=2;
                div++;
            }
            st.erase(xx);
        }

//        if(div==-1)cout<<

        cout<<div<<endl;

    }

    return 0;
}


//#pragma comment(linker, "/stack:200000000")
#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define ULL unsigned long long
const LL INF=1LL<<60;
const double PI = acos(-1.0);

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

//// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//cout<<*X.find_by_order(1)<<endl;
//cout<<X.order_of_key(-5)<<endl;

//typedef tree<
//pll,
//null_type,
//less< pll >,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define mem(x,y) 	memset(x,y,sizeof x )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
#define lc			tree[idx*2]
#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
LL X[4]={0,0,-1,1};
LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));} // check bit
inline int setBit(int N,int pos){	return N=N | (1<<pos);}// set bit
inline int unsetBit(int N,int pos){	return N=( N & ( ~( 1<<pos ) ) );}// unset bit
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }// toggle bit

LL modMul(LL a, LL b,LL mod){

    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}

LL powerMod(LL a,LL b,LL mod){
	if(b==0)return 1LL%mod;
	LL x=powerMod(a,b/2,mod);
	x = (x%mod*x%mod)%mod;
	if(b%2==1)x = (x%mod*a%mod)%mod;
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
const int mx = 2e5+7;

LL arr[mx];

int main(){

//    BOOST;
//    READ;
//    WRITE;
    int t;

    cin>>t;
    while(t--){

        LL n,m;
        priority_queue<LL> q;
        cin>>n>>m;
        LL sum = 0;
        for(int i=1;i<=m;i++){
            LL d;cin>>d;
            q.push(d);
            arr[i] = d;
            sum += d;
        }

        if(sum < n){
            cout<<-1<<endl;
            continue;
        }

        multiset<LL> st;
        LL tomake = n;
        while(!q.empty()){
            LL x = q.top();
            if(x<=tomake)tomake -= x;
            else st.insert(x);
            q.pop();
        }
        int div = 0;

//        cout<<tomake<<endl;
        while(tomake>0){
            auto xx = st.lower_bound(tomake);
            LL x = *xx;
//            cout<<x<<endl;
            while(x>0){
//                cout<<tomake<<" "<<x<<" "<<div<<endl;
                if( tomake==0 )break;
                if(x==tomake){
                    tomake = 0;break;
                }
                if(tomake >= x/2)tomake -= x/2;
                x/=2;
                div++;
            }
            st.erase(xx);
        }

        cout<<div<<endl;

    }

    return 0;
}


//#pragma comment(linker, "/stack:200000000")
#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define ULL unsigned long long
const LL INF=1LL<<60;
const double PI = acos(-1.0);

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

//// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//cout<<*X.find_by_order(1)<<endl;
//cout<<X.order_of_key(-5)<<endl;

//typedef tree<
//pll,
//null_type,
//less< pll >,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define mem(x,y) 	memset(x,y,sizeof x )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
#define lc			tree[idx*2]
#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
LL X[4]={0,0,-1,1};
LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));} // check bit
inline int setBit(int N,int pos){	return N=N | (1<<pos);}// set bit
inline int unsetBit(int N,int pos){	return N=( N & ( ~( 1<<pos ) ) );}// unset bit
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }// toggle bit

LL modMul(LL a, LL b,LL mod){

    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}

LL powerMod(LL a,LL b,LL mod){
	if(b==0)return 1LL%mod;
	LL x=powerMod(a,b/2,mod);
	x = (x%mod*x%mod)%mod;
	if(b%2==1)x = (x%mod*a%mod)%mod;
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
const int mx = 2e5+7;

multiset<LL> st;

int cnt[70];

int main(){

//    BOOST;
//    READ;
//    WRITE;
    int t;

    cin>>t;
    while(t--){

        LL n,m;
        mem(cnt,0);
        LL sum = 0;
        cin>>n>>m;
        FOR(i,m){
            LL x;
            cin>>x;
            int p=0;
            while(!((1LL<<p)&x))p++;
            cnt[p]++;
            st.insert(x);
            sum += x;
//            cout<<p<<endl;
        }

        if(sum < n){
            cout<<-1<<endl;
            continue;
        }

        LL tomake = n;
        int div = 0;
        for(int i=0;i<62;i++){
            if((1LL<<i)&tomake){
                LL now = (1LL<<i);

                LL cur = now;
                vl used;
                for(int j=61;j>=0;j--){
                    if(cnt[j]>0){
                        int xd = 0;
                        while( (1LL<<j) <= now ){
                            if(xd > cnt[j])break;
                            now -= (1LL<<j);
                            used.pb(j);
                            xd++;
                        }
                    }
                }

//                cout<<now<<endl;

                if(now==0){
                    for(int xx:used)cnt[xx]--;
                }
                else{
                    int j = i;
                    while(cnt[j]==0 && j<62){
                        j++;
                        div++;
                    }
                    cnt[j]--;
                }
            }
        }

        cout<<div<<endl;

    }

    return 0;
}


//#pragma comment(linker, "/stack:200000000")
#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define ULL unsigned long long
const LL INF=1LL<<60;
const double PI = acos(-1.0);

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

//// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//cout<<*X.find_by_order(1)<<endl;
//cout<<X.order_of_key(-5)<<endl;

//typedef tree<
//pll,
//null_type,
//less< pll >,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define mem(x,y) 	memset(x,y,sizeof x )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
#define lc			tree[idx*2]
#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
LL X[4]={0,0,-1,1};
LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));} // check bit
inline int setBit(int N,int pos){	return N=N | (1<<pos);}// set bit
inline int unsetBit(int N,int pos){	return N=( N & ( ~( 1<<pos ) ) );}// unset bit
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }// toggle bit

LL modMul(LL a, LL b,LL mod){

    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}

LL powerMod(LL a,LL b,LL mod){
	if(b==0)return 1LL%mod;
	LL x=powerMod(a,b/2,mod);
	x = (x%mod*x%mod)%mod;
	if(b%2==1)x = (x%mod*a%mod)%mod;
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
const int mx = 2e5+7;

LL arr[mx];

int main(){

//    BOOST;
//    READ;
//    WRITE;
    int t;

    cin>>t;
    while(t--){

        LL n,m;
        priority_queue<LL> q;
        cin>>n>>m;
        LL sum = 0;
        for(int i=1;i<=m;i++){
            LL d;cin>>d;
            q.push(d);
            arr[i] = d;
            sum += d;
        }

        if(sum < n){
            cout<<-1<<endl;
            continue;
        }

        multiset<LL> st;
        LL tomake = n;
        while(!q.empty()){
            LL x = q.top();
            if(x<=tomake)tomake -= x;
            else st.insert(x);
            q.pop();
        }
        int div = 0;

//        cout<<tomake<<endl;
        while(tomake>0){

            if(st.empty()){
                div = -1;
                break;
            }

            auto xx = st.lower_bound(tomake);
            LL x = *xx;
//            cout<<x<<endl;
            while(x>0){
//                cout<<tomake<<" "<<x<<" "<<div<<endl;
                if( tomake==0 )break;
                if(tomake >= x){
                    tomake -= x;
                }
                x/=2;
                div++;
            }
            st.erase(xx);
        }

//        if(div==-1)cout<<

        cout<<div<<endl;

    }

    return 0;
}


//#pragma comment(linker, "/stack:200000000")
#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define ULL unsigned long long
const LL INF=1LL<<60;
const double PI = acos(-1.0);

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

//// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//cout<<*X.find_by_order(1)<<endl;
//cout<<X.order_of_key(-5)<<endl;

//typedef tree<
//pll,
//null_type,
//less< pll >,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define mem(x,y) 	memset(x,y,sizeof x )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
#define lc			tree[idx*2]
#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
LL X[4]={0,0,-1,1};
LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));} // check bit
inline int setBit(int N,int pos){	return N=N | (1<<pos);}// set bit
inline int unsetBit(int N,int pos){	return N=( N & ( ~( 1<<pos ) ) );}// unset bit
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }// toggle bit

LL modMul(LL a, LL b,LL mod){

    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}

LL powerMod(LL a,LL b,LL mod){
	if(b==0)return 1LL%mod;
	LL x=powerMod(a,b/2,mod);
	x = (x%mod*x%mod)%mod;
	if(b%2==1)x = (x%mod*a%mod)%mod;
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
const int mx = 2e5+7;

LL arr[mx];

int main(){

//    BOOST;
//    READ;
//    WRITE;
    int t;

    cin>>t;
    while(t--){

        LL n,m;
        priority_queue<LL> q;
        cin>>n>>m;
        LL sum = 0;
        for(int i=1;i<=m;i++){
            LL d;cin>>d;
            q.push(d);
            arr[i] = d;
            sum += d;
        }

        if(sum < n){
            cout<<-1<<endl;
            continue;
        }

        multiset<LL> st;
        LL tomake = n;
        while(!q.empty()){
            LL x = q.top();
            if(x<=tomake)tomake -= x;
            else st.insert(x);
            q.pop();
        }
        int div = 0;

//        cout<<tomake<<endl;
        while(tomake>0){

            if(st.empty()){
                div = -1;
                break;
            }

            auto xx = st.lower_bound(tomake);
            LL x = *xx;
//            cout<<x<<endl;
            while(x>0){
//                cout<<tomake<<" "<<x<<" "<<div<<endl;
                if( tomake==0 )break;
//                if(x==tomake){
//                    tomake = 0;break;
//                }
                if(tomake >= x){
                    tomake -= x;break;
                }
                x/=2;
                div++;
            }
            st.erase(xx);
        }

//        if(div==-1)cout<<

        cout<<div<<endl;

    }

    return 0;
}


//#pragma comment(linker, "/stack:200000000")
#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define ULL unsigned long long
const LL INF=1LL<<60;
const double PI = acos(-1.0);

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

//// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//cout<<*X.find_by_order(1)<<endl;
//cout<<X.order_of_key(-5)<<endl;

//typedef tree<
//pll,
//null_type,
//less< pll >,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define mem(x,y) 	memset(x,y,sizeof x )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
#define lc			tree[idx*2]
#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
LL X[4]={0,0,-1,1};
LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));} // check bit
inline int setBit(int N,int pos){	return N=N | (1<<pos);}// set bit
inline int unsetBit(int N,int pos){	return N=( N & ( ~( 1<<pos ) ) );}// unset bit
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }// toggle bit

LL modMul(LL a, LL b,LL mod){

    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}

LL powerMod(LL a,LL b,LL mod){
	if(b==0)return 1LL%mod;
	LL x=powerMod(a,b/2,mod);
	x = (x%mod*x%mod)%mod;
	if(b%2==1)x = (x%mod*a%mod)%mod;
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
const int mx = 2e5+7;

multiset<LL> st;

int cnt[70];

int main(){

//    BOOST;
//    READ;
//    WRITE;
    int t;

    cin>>t;
    while(t--){

        LL n,m;
        mem(cnt,0);
        LL sum = 0;
        cin>>n>>m;
        FOR(i,m){
            LL x;
            cin>>x;
            int p=0;
            while(!((1LL<<p)&x))p++;
            cnt[p]++;
            st.insert(x);
            sum += x;
//            cout<<p<<endl;
        }

        if(sum < n){
            cout<<-1<<endl;
            continue;
        }

        LL tomake = n;
        int div = 0;
        for(int i=0;i<62;i++){
            if((1LL<<i)&tomake){
                LL now = (1LL<<i);

                LL cur = now;
                vl used;
                for(int j=61;j>=0;j--){
                    if(cnt[j]>0){
                        int xd = 0;
                        while( (1LL<<j) <= now ){
                            if(xd >= cnt[j])break;
//                            cout<<now<<endl;
                            now -= (1LL<<j);
                            used.pb(j);
                            xd++;
                        }
                    }
                }

//                cout<<now<<endl;

                if(now==0){
                    for(int xx:used)cnt[xx]--;
                }
                else{
                    int j = i;
                    while(cnt[j]==0 && j<62){
                        j++;
                        div++;
                    }
                    cnt[j]--;
                }
            }
        }

        cout<<div<<endl;

    }

    return 0;
}


//#pragma comment(linker, "/stack:200000000")
#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define ULL unsigned long long
const LL INF=1LL<<60;
const double PI = acos(-1.0);

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

//// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//cout<<*X.find_by_order(1)<<endl;
//cout<<X.order_of_key(-5)<<endl;

//typedef tree<
//pll,
//null_type,
//less< pll >,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define mem(x,y) 	memset(x,y,sizeof x )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
#define lc			tree[idx*2]
#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
LL X[4]={0,0,-1,1};
LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));} // check bit
inline int setBit(int N,int pos){	return N=N | (1<<pos);}// set bit
inline int unsetBit(int N,int pos){	return N=( N & ( ~( 1<<pos ) ) );}// unset bit
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }// toggle bit

LL modMul(LL a, LL b,LL mod){

    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}

LL powerMod(LL a,LL b,LL mod){
	if(b==0)return 1LL%mod;
	LL x=powerMod(a,b/2,mod);
	x = (x%mod*x%mod)%mod;
	if(b%2==1)x = (x%mod*a%mod)%mod;
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
const int mx = 2e5+7;

multiset<LL> st;

int cnt[70];

int main(){

//    BOOST;
//    READ;
//    WRITE;
    int t;

    cin>>t;
    while(t--){

        LL n,m;
        mem(cnt,0);
        LL sum = 0;
        cin>>n>>m;
        FOR(i,m){
            LL x;
            cin>>x;
            int p=0;
            while(!((1LL<<p)&x))p++;
            cnt[p]++;
//            st.insert(x);
            sum += x;
//            cout<<p<<endl;
        }

        if(sum < n){
            cout<<-1<<endl;
            continue;
        }

        LL tomake = n;
        int div = 0;
        bool fnd = 1;
        for(int i=0;i<61;i++){
            if(!fnd)break;
            if((1LL<<i)&tomake){
                LL now = (1LL<<i);
                if(!fnd)break;
                LL cur = now;
                vl used;
                for(int j=60;j>=0;j--){
                    if(cnt[j]>0){
                        int xd = 0;
                        while( (1LL<<j) <= now ){
                            if(xd >= cnt[j])break;
                            now -= (1LL<<j);
                            used.pb(j);
                            xd++;
                        }
                    }
                }

//                cout<<now<<endl;

                if(now==0){
                    for(int xx:used)cnt[xx]--;
                }
                else{
                    int j = i;
                    int xx = 0;
                    while(cnt[j]==0 && j<61){
                        j++;
//                        div++;
                        xx++;
                    }
                    if(cnt[j]>0){
                        cnt[j]--;
                        div += xx;
                        for(int jj=j-1;jj>=i;jj--)cnt[jj]++;
                    }
                    else{
                        fnd = 0;
                    }
                }
            }
        }

        if(!fnd)div = -1;
        cout<<div<<endl;

    }

    return 0;
}


//#pragma comment(linker, "/stack:200000000")
#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define ULL unsigned long long
const LL INF=1LL<<60;
const double PI = acos(-1.0);

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

//// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//cout<<*X.find_by_order(1)<<endl;
//cout<<X.order_of_key(-5)<<endl;

//typedef tree<
//pll,
//null_type,
//less< pll >,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define mem(x,y) 	memset(x,y,sizeof x )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
#define lc			tree[idx*2]
#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
LL X[4]={0,0,-1,1};
LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));} // check bit
inline int setBit(int N,int pos){	return N=N | (1<<pos);}// set bit
inline int unsetBit(int N,int pos){	return N=( N & ( ~( 1<<pos ) ) );}// unset bit
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }// toggle bit

LL modMul(LL a, LL b,LL mod){

    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}

LL powerMod(LL a,LL b,LL mod){
	if(b==0)return 1LL%mod;
	LL x=powerMod(a,b/2,mod);
	x = (x%mod*x%mod)%mod;
	if(b%2==1)x = (x%mod*a%mod)%mod;
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
const int mx = 2e5+7;

LL arr[mx];

int main(){

//    BOOST;
//    READ;
//    WRITE;
    int t;

    cin>>t;
    while(t--){

        LL n,m;
        priority_queue<LL> q;
        cin>>n>>m;
        LL sum = 0;
        for(int i=1;i<=m;i++){
            LL d;cin>>d;
            q.push(d);
            arr[i] = d;
            sum += d;
        }

        if(sum < n){
            cout<<-1<<endl;
            continue;
        }

        multiset<LL> st;
        LL tomake = n;
        while(!q.empty()){
            LL x = q.top();
            if(x<=tomake)tomake -= x;
            else st.insert(x);
            q.pop();
        }
        int div = 0;

//        cout<<tomake<<endl;
        while(tomake>0){
            auto xx = st.lower_bound(tomake);
            LL x = *xx;
//            cout<<x<<endl;
            while(x>0){
//                cout<<tomake<<" "<<x<<" "<<div<<endl;
                if( tomake==0 )break;
//                if(x==tomake){
//                    tomake = 0;break;
//                }
                if(tomake >= x/2)tomake -= x/2;
                x/=2;
                div++;
            }
            st.erase(xx);
        }

        cout<<div<<endl;

    }

    return 0;
}


//#pragma comment(linker, "/stack:200000000")
#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define ULL unsigned long long
const LL INF=1LL<<60;
const double PI = acos(-1.0);

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

//// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//cout<<*X.find_by_order(1)<<endl;
//cout<<X.order_of_key(-5)<<endl;

//typedef tree<
//pll,
//null_type,
//less< pll >,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define mem(x,y) 	memset(x,y,sizeof x )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
#define lc			tree[idx*2]
#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
LL X[4]={0,0,-1,1};
LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));} // check bit
inline int setBit(int N,int pos){	return N=N | (1<<pos);}// set bit
inline int unsetBit(int N,int pos){	return N=( N & ( ~( 1<<pos ) ) );}// unset bit
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }// toggle bit

LL modMul(LL a, LL b,LL mod){

    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}

LL powerMod(LL a,LL b,LL mod){
	if(b==0)return 1LL%mod;
	LL x=powerMod(a,b/2,mod);
	x = (x%mod*x%mod)%mod;
	if(b%2==1)x = (x%mod*a%mod)%mod;
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
const int mx = 2e5+7;

LL arr[mx];

int main(){

//    BOOST;
//    READ;
//    WRITE;
    int t;

    cin>>t;
    while(t--){

        LL n,m;
        priority_queue<LL> q;
        cin>>n>>m;
        LL sum = 0;
        for(int i=1;i<=m;i++){
            LL d;cin>>d;
            q.push(d);
            arr[i] = d;
            sum += d;
        }

        if(sum < n){
            cout<<-1<<endl;
            continue;
        }

        multiset<LL> st;
        LL tomake = n;
        while(!q.empty()){
            LL x = q.top();
            if(x<=tomake)tomake -= x;
            else st.insert(x);
            q.pop();
        }
        int div = 0;

//        cout<<tomake<<endl;
        while(tomake>0){
            auto xx = st.lower_bound(tomake);
            LL x = *xx;
//            cout<<x<<endl;
            while(x>0){
//                cout<<tomake<<" "<<x<<" "<<div<<endl;
                if( tomake==0 )break;
//                if(x==tomake){
//                    tomake = 0;break;
//                }
                if(tomake >= x){
                    tomake -= x;break;
                }
                x/=2;
                div++;
            }
            st.erase(xx);
        }

        cout<<div<<endl;

    }

    return 0;
}


//#pragma comment(linker, "/stack:200000000")
#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define ULL unsigned long long
const LL INF=1LL<<60;
const double PI = acos(-1.0);

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

//// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//cout<<*X.find_by_order(1)<<endl;
//cout<<X.order_of_key(-5)<<endl;

//typedef tree<
//pll,
//null_type,
//less< pll >,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define mem(x,y) 	memset(x,y,sizeof x )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
#define lc			tree[idx*2]
#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
LL X[4]={0,0,-1,1};
LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));} // check bit
inline int setBit(int N,int pos){	return N=N | (1<<pos);}// set bit
inline int unsetBit(int N,int pos){	return N=( N & ( ~( 1<<pos ) ) );}// unset bit
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }// toggle bit

LL modMul(LL a, LL b,LL mod){

    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}

LL powerMod(LL a,LL b,LL mod){
	if(b==0)return 1LL%mod;
	LL x=powerMod(a,b/2,mod);
	x = (x%mod*x%mod)%mod;
	if(b%2==1)x = (x%mod*a%mod)%mod;
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
const int mx = 2e5+7;

LL arr[mx];

int main(){

//    BOOST;
//    READ;
//    WRITE;
    int t;

    cin>>t;
    while(t--){

        LL n,m;
        priority_queue<LL> q;
        cin>>n>>m;
        LL sum = 0;
        for(int i=1;i<=m;i++){
            LL d;cin>>d;
            q.push(d);
            arr[i] = d;
            sum += d;
        }

        if(sum < n){
            cout<<-1<<endl;
            continue;
        }

        multiset<LL> st;
        LL tomake = n;
        while(!q.empty()){
            LL x = q.top();
            if(x<=tomake)tomake -= x;
            else st.insert(x);
            q.pop();
        }
        int div = 0;

//        cout<<tomake<<endl;
        while(tomake>0){

            if(st.empty()){
                div = -1;
                break;
            }

            auto xx = st.begin();
            LL x = *xx;
//            cout<<x<<endl;
            while(x>0){
//                cout<<tomake<<" "<<x<<" "<<div<<endl;
                if( tomake==0 )break;
                if(tomake >= x){
                    tomake -= x;
                }
                if(tomake==0)break;
                x/=2;
                div++;
            }
            st.erase(xx);
        }

//        if(div==-1)cout<<

        cout<<div<<endl;

    }

    return 0;
}


//#pragma comment(linker, "/stack:200000000")
#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define ULL unsigned long long
const LL INF=1LL<<60;
const double PI = acos(-1.0);

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

//// Including Policy Based DS
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//cout<<*X.find_by_order(1)<<endl;
//cout<<X.order_of_key(-5)<<endl;

//typedef tree<
//pll,
//null_type,
//less< pll >,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

#define READ 		freopen("in.txt","r",stdin)
#define WRITE  		freopen("out.txt","w",stdout)
#define BOOST		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sf 			scanf
#define pf 			printf
#define F  			first
#define S  			second
#define pb 			push_back
#define NL			pf("\n")
#define ALL(v)		v.begin(),v.end()
#define si(x)		sf("%d",&x);
#define sii(x,y)	sf("%d%d",&x,&y);
#define siii(x,y,z)	sf("%d%d%d",&x,&y,&z);
#define sl(x)		sf("%lld",&x);
#define sll(x,y)	sf("%lld%lld",&x,&y);
#define slll(x,y,z)	sf("%lld%lld%lld",&x,&y,&z);
#define mem(x,y) 	memset(x,y,sizeof x )
#define ch 			printf("Came Here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
#define SV(v)		sort(v.begin(),v.end())
#define SVR(v,cmp)	sort(v.begin(),v.end(),cmp)
#define FOR(i,n)	for(int i=0;i<n;i++)
#define cnd			tree[idx]
#define lc			tree[idx*2]
#define rc			tree[idx*2+1]
#define lnd 		(2*idx),(b),((b+e)/2)
#define rnd 		((2*idx)+1),(((b+e)/2)+1),(e)

// graph direction array [4]
LL X[4]={0,0,-1,1};
LL Y[4]={1,-1,0,0};
// graph direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Bishop direction array [8]
//int X[8]={0,0,1,-1,-1,1,1,-1};
//int Y[8]={1,-1,0,0,-1,-1,1,1};
// Knight Direction Array
//int KX[8] = {1,1,2,2,-1,-1,-2,-2};
//int KY[8] = {2,-2,1,-1,2,-2,1,-1};

inline bool checkBit(int N,int pos){return (bool)(N & (1<<pos));} // check bit
inline int setBit(int N,int pos){	return N=N | (1<<pos);}// set bit
inline int unsetBit(int N,int pos){	return N=( N & ( ~( 1<<pos ) ) );}// unset bit
inline int toggleBit(int N,int pos){ return N = ( N ^(1<<pos) ); }// toggle bit

LL modMul(LL a, LL b,LL mod){

    LL ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}

LL powerMod(LL a,LL b,LL mod){
	if(b==0)return 1LL%mod;
	LL x=powerMod(a,b/2,mod);
	x = (x%mod*x%mod)%mod;
	if(b%2==1)x = (x%mod*a%mod)%mod;
	return x%mod;
}

LL lcm( LL a,LL b ){
	LL g = __gcd(a,b);
	return (a*b)/g;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
const int mx = 2e5+7;

multiset<LL> st;

int cnt[70];

int main(){

//    BOOST;
//    READ;
//    WRITE;
    int t;

    cin>>t;
    while(t--){

        LL n,m;
        mem(cnt,0);
        LL sum = 0;
        cin>>n>>m;
        FOR(i,m){
            LL x;
            cin>>x;
            int p=0;
            while(!((1LL<<p)&x))p++;
            cnt[p]++;
//            st.insert(x);
            sum += x;
//            cout<<p<<endl;
        }

        if(sum < n){
            cout<<-1<<endl;
            continue;
        }

        LL tomake = n;
        int div = 0;
        bool fnd = 1;
        for(int i=0;i<61;i++){
            if(!fnd)break;
            if((1LL<<i)&tomake){
                LL now = (1LL<<i);
                if(!fnd)break;
                LL cur = now;
                vl used;
                for(int j=60;j>=0;j--){
                    if(cnt[j]>0){
                        int xd = 0;
                        while( (1LL<<j) <= now ){
                            if(xd >= cnt[j])break;
                            now -= (1LL<<j);
                            used.pb(j);
                            xd++;
                        }
                    }
                }

//                cout<<now<<endl;

                if(now==0){
                    for(int xx:used)cnt[xx]--;
                }
                else{
                    int j = i;
                    int xx = 0;
                    while(cnt[j]==0 && j<61){
                        j++;
//                        div++;
                        xx++;
                    }
                    if(cnt[j]==1){
                        cnt[j]--;
                        div += xx;
                        for(int jj=j-1;jj>=i;jj--)cnt[jj]++;
                    }
                    else{
                        fnd = 0;
                    }
                }
            }
        }

        if(!fnd)div = -1;
        cout<<div<<endl;

    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long t;
map<long long,long long > mp;
bool sastavi(long long a,long long k){
    if(mp[a]>=k){
        mp[a]-=k;
        return true;
    }
    else{
        if(a==1)
        return false;
        if(mp[a]>0)
            k-=mp[a];
        mp[a]=0;
        return sastavi(a/2,k*2);
    }
}
long long nadji(long long  a){
    if(mp[a]>=1){
        mp[a]-=1;
        return a;
    }
    else{
        long long x=pow(2,61);
        if(a>=x){
            return -1;
        }
        else{
            return nadji(a*2);
        }
    }
}
long long dodji(long long  a,long long  k){
    long long  br=0;
    mp[a]--;
    while(a>k){
        a=a/2;
        br++;
        mp[a]++;
    }
    return br;
}
long long  doing1(long long  n){
    for(long long  i=0;i<=62;i++){
        long long  k=pow(2,i);
        if(k>n)
            break;
        long long  l=k|n;
        if(l==n){
            if(mp[k]>0){
                mp[k]--;
                n-=k;
            }
    }
    }
    return n;
}
long long doing2(long long n){
    for(long long i=0;i<=62;i++){
        long long k=pow(2,i);
        if(k>n)
            break;
        long long l=k|n;
        long long s=1;
        if(l==n&&sastavi(k,s)){
            n-=k;
        }
    }
    return n;
}
long long  doing3(long long  n){
    long long  res=0;
    for(long long i=62;i>=0;i--){
        long long k=pow(2,i);
        long long l=k|n;
        if(l==n){
            long long a=nadji(k);
            if(a==-1){
                return -1;
            }
            else{
                n-=k;
                res+=dodji(a,k);
            }
        }
    }
    return res;
}
int  main()
{
    scanf("%lld",&t);
    t++;
    int x=0;
    while(t>1){
        t--;
        x++;
        long long  n,m;
        scanf("%lld",&n);
        scanf("%lld",&m);
        for(long long i=0;i<m;i++){
            long long a;
            scanf("%lld",&a);
            mp[a]++;
        }
        n=doing1(n);
        if(n==0){
            cout<<0<<endl;
            continue;
        }
        n=doing2(n);

        if(n==0){
            cout<<0<<endl;
            continue;
        }
        if(t>1)
        n=doing3(n);

        cout<<n<<endl;
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long t;
map<long long,long long > mp;
bool sastavi(long long a,long long k){
    if(mp[a]>=k){
        mp[a]-=k;
        return true;
    }
    else{
        if(a==1)
        return false;
        if(mp[a]>0)
            k-=mp[a];
        mp[a]=0;
        return sastavi(a/2,k*2);
    }
}
long long nadji(long long  a){
    if(mp[a]>=1){
        mp[a]-=1;
        return a;
    }
    else{
        long long x=pow(2,61);
        if(a>=x){
            return -1;
        }
        else{
            return nadji(a*2);
        }
    }
}
long long dodji(long long  a,long long  k){
    long long  br=0;
    mp[a]--;
    while(a>k){
        a=a/2;
        br++;
        mp[a]++;
    }
    return br;
}
long long  doing1(long long  n){
    for(long long  i=0;i<=62;i++){
        long long  k=pow(2,i);
        if(k>n)
            break;
        long long  l=k|n;
        if(l==n){
            if(mp[k]>0){
                mp[k]--;
                n-=k;
            }
    }
    }
    return n;
}
long long doing2(long long n){
    for(long long i=0;i<=62;i++){
        long long k=pow(2,i);
        if(k>n)
            break;
        long long l=k|n;
        long long s=1;
        if(l==n&&sastavi(k,s)){
            n-=k;
        }
    }
    return n;
}
long long  doing3(long long  n){
    long long  res=0;
    for(long long i=62;i>=0;i--){
        long long k=pow(2,i);
        long long l=k|n;
        if(l==n){
            long long a=nadji(k);
            if(a==-1){
                return -1;
            }
            else{
                n-=k;
                res+=dodji(a,k);
            }
        }
    }
    return res;
}
int  main()
{
    scanf("%lld",&t);
    t++;
    int x=0;
    while(t>1){
        t--;
        x++;
        long long  n,m;
        scanf("%lld",&n);
        scanf("%lld",&m);
        for(long long i=0;i<m;i++){
            long long a;
            scanf("%lld",&a);
            mp[a]++;
        }
        n=doing1(n);
        if(n==0){
            cout<<0<<endl;
            continue;
        }
        if(t<10){
                        n=doing2(n);

        if(n==0){
            cout<<0<<endl;
            continue;
        }
        n=doing3(n);
        }
        cout<<n<<endl;
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long t;
map<long long,long long > mp;
bool sastavi(long long a,long long k){
    if(mp[a]>=k){
        mp[a]-=k;
        return true;
    }
    else{
        if(a==1)
        return false;
        if(mp[a]>0)
            k-=mp[a];
        mp[a]=0;
        return sastavi(a/2,k*2);
    }
}
long long nadji(long long  a){
    if(mp[a]>=1){
        mp[a]-=1;
        return a;
    }
    else{
        long long x=pow(2,61);
        if(a>=x){
            return -1;
        }
        else{
            return nadji(a*2);
        }
    }
}
long long dodji(long long  a,long long  k){
    long long  br=0;
    mp[a]--;
    while(a>k){
        a=a/2;
        br++;
        mp[a]++;
    }
    return br;
}
long long  doing1(long long  n){
    for(long long  i=0;i<=62;i++){
        long long  k=pow(2,i);
        if(k>n)
            break;
        long long  l=k|n;
        if(l==n){
            if(mp[k]>0){
                mp[k]--;
                n-=k;
            }
    }
    }
    return n;
}
long long doing2(long long n){
    for(long long i=0;i<=62;i++){
        long long k=pow(2,i);
        if(k>n)
            break;
        long long l=k|n;
        long long s=1;
        if(l==n&&sastavi(k,s)){
            n-=k;
        }
    }
    return n;
}
long long  doing3(long long  n){
    long long  res=0;
    for(long long i=62;i>=0;i--){
        long long k=pow(2,i);
        long long l=k|n;
        if(l==n){
            long long a=nadji(k);
            if(a==-1){
                return -1;
            }
            else{
                n-=k;
                res+=dodji(a,k);
            }
        }
    }
    return res;
}
int  main()
{
    scanf("%lld",&t);
    t++;
    int x=0;
    while(t>1){
        t--;
        x++;
        long long  n,m;
        scanf("%lld",&n);
        scanf("%lld",&m);
        for(long long i=0;i<m;i++){
            long long a;
            scanf("%lld",&a);
            mp[a]++;
        }
        n=doing1(n);
        if(n==0){
            cout<<0<<endl;
            continue;
        }
        if(x<10){
                        n=doing2(n);

        if(n==0){
            cout<<0<<endl;
            continue;
        }
        n=doing3(n);
        }
        cout<<n<<endl;
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long t;
map<long long,long long > mp;
bool sastavi(long long a,long long k){
    if(mp[a]>=k){
        mp[a]-=k;
        return true;
    }
    else{
        if(a==1)
        return false;
        if(mp[a]>0)
            k-=mp[a];
        mp[a]=0;
        return sastavi(a/2,k*2);
    }
}
long long nadji(long long  a){
    if(mp[a]>=1){
        mp[a]-=1;
        return a;
    }
    else{
        long long x=pow(2,61);
        if(a>=x){
            return -1;
        }
        else{
            return nadji(a*2);
        }
    }
}
long long dodji(long long  a,long long  k){
    long long  br=0;
    mp[a]--;
    while(a>k){
        a=a/2;
        br++;
        mp[a]++;
    }
    return br;
}
long long  doing1(long long  n){
    for(long long  i=0;i<=62;i++){
        long long  k=pow(2,i);
        if(k>n)
            break;
        long long  l=k|n;
        if(l==n){
            if(mp[k]>0){
                mp[k]--;
                n-=k;
            }
    }
    }
    return n;
}
long long doing2(long long n){
    for(long long i=0;i<=62;i++){
        long long k=pow(2,i);
        if(k>n)
            break;
        long long l=k|n;
        long long s=1;
        if(l==n&&sastavi(k,s)){
            n-=k;
        }
    }
    return n;
}
long long  doing3(long long  n){
    long long  res=0;
    for(long long i=62;i>=0;i--){
        long long k=pow(2,i);
        long long l=k|n;
        if(l==n){
            long long a=nadji(k);
            if(a==-1){
                return -1;
            }
            else{
                n-=k;
                res+=dodji(a,k);
            }
        }
    }
    return res;
}
int  main()
{
    scanf("%lld",&t);
    t++;
    long long sum=0;
    while(t>1){
        t--;
        sum=0;
        long long  n,m;
        scanf("%lld",&n);
        scanf("%lld",&m);
        for(long long i=0;i<m;i++){
            long long a;
            scanf("%lld",&a);
            mp[a]++;
            sum+=a;
        }
        if(sum<n){
            cout<<-1<<endl;
            continue;
        }
        n=doing1(n);
        if(n==0){
            cout<<0<<endl;
            continue;
        }

    n=doing2(n);
        if(n==0){
            cout<<0<<endl;
            continue;
        }
        n=doing3(n);
        cout<<n<<endl;
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long  t;
map<long long ,long long > mp;
bool sastavi(long long  a,long long  k){
    if(mp[a]>=k){
        mp[a]-=k;
        return true;
    }
    else{
        if(a==1)
        return false;
        k-=mp[a];
        mp[a]=0;
        k*=2;
        return sastavi(a/2,k);
    }
}
long long  nadji(long long  a){
    if(mp[a]>=1){
        mp[a]-=1;
        return a;
    }
    else{
        if(a>=1000000000000000000){
            return -1;
        }
        else{
            return nadji(a*2);
        }
    }
}
long long  dodji(long long  a,long long  k){
    long long  br=0;
    mp[a]--;
    while(a>k){
        a=a/2;
        br++;
        mp[a]++;
    }
    return br;
}
long long  doing1(long long  n){
    for(long long  i=0;i<61;i++){
        long long  k=pow(2,i);
        long long  l=k|n;
        if(l==n){
            if(mp[k]>0){
                mp[k]--;
                n-=k;
            }
        }
    }
    return n;
}
long long  doing2(long long  n){
    for(long long  i=0;i<61;i++){
        long long  k=pow(2,i);
        long long  l=k|n;
        if(l==n&&sastavi(k,1)){
            n-=k;
        }
    }
    return n;
}
long long  doing3(long long  n){
    long long  res=0;
    for(long long  i=60;i>=0;i--){
        long long  k=pow(2,i);
        long long  l=k|n;
        if(l==n){
            long long  a=nadji(k);
            if(a==-1){
                return -1;
            }
            else{
                n-=k;
                res+=dodji(a,k);
            }
        }
    }
    return res;
}
int  main()
{
    scanf("%lld",&t);
    t++;
    while(t>1){
        t--;
        long long  n,m;
        scanf("%lld",&n);
        scanf("%lld",&m);
        for(long long  i=0;i<m;i++){
            long long  a;
            scanf("%lld",&a);
            mp[a]++;
        }
        n=doing1(n);
        if(n==0){
            cout<<0<<endl;
            continue;
        }
        n=doing2(n);
        if(n==0){
            cout<<0<<endl;
            continue;
        }
        n=doing3(n);

        cout<<n<<endl;
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long t;
map<long long,long long > mp;
bool sastavi(long long a,long long k){
    if(mp[a]>=k){
        mp[a]-=k;
        return true;
    }
    else{
        if(a==1)
        return false;
        if(mp[a]>0)
            k-=mp[a];
        mp[a]=0;
        return sastavi(a/2,k*2);
    }
}
long long nadji(long long  a){
    if(mp[a]>=1){
        mp[a]-=1;
        return a;
    }
    else{
        if(a>=pow(2,62)){
            return -1;
        }
        else{
            return nadji(a*2);
        }
    }
}
long long dodji(long long  a,long long  k){
    long long  br=0;
    mp[a]--;
    while(a>k){
        a=a/2;
        br++;
        mp[a]++;
    }
    return br;
}
long long  doing1(long long  n){
    for(long long  i=0;i<=62;i++){
        long long  k=pow(2,i);
        if(k>n)
            break;
        long long  l=k|n;
        if(l==n){
            if(mp[k]>0){
                mp[k]--;
                n-=k;
            }
    }
    }
    return n;
}
long long doing2(long long n){
    for(long long i=0;i<=62;i++){
        long long k=pow(2,i);
        if(k>n)
            break;
        long long l=k|n;
        long long s=1;
        if(l==n&&sastavi(k,s)){
            n-=k;
        }
    }
    return n;
}
long long  doing3(long long  n){
    long long  res=0;
    for(long long i=62;i>=0;i--){
        long long k=pow(2,i);
        long long l=k|n;
        if(l==n){
            long long a=nadji(k);
            if(a==-1){
                return -1;
            }
            else{
                n-=k;
                res+=dodji(a,k);
            }
        }
    }
    return res;
}
int  main()
{
    scanf("%lld",&t);
    t++;
    while(t>1){
        t--;
        long long  n,m;
        scanf("%lld",&n);
        scanf("%lld",&m);
        for(long long i=0;i<m;i++){
            long long a;
            scanf("%lld",&a);
            mp[a]++;
        }
        n=doing1(n);
        if(n==0){
            cout<<0<<endl;
            continue;
        }
        n=doing2(n);
        if(n==0){
            cout<<0<<endl;
            continue;
        }
        n=doing3(n);

        cout<<n<<endl;
        mp.clear();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long t;
map<long long,long long > mp;
bool sastavi(long long a,long long k){
    if(mp[a]>=k){
        mp[a]-=k;
        return true;
    }
    else{
        if(a==1)
        return false;
        if(mp[a]>0)
            k-=mp[a];
        return sastavi(a/2,k*2);
    }
}
long long nadji(long long  a){
    if(mp[a]>0){
        mp[a]--;
        return a;
    }
    else{
        long long x=pow(2,61);
        if(a>=x){
            return -1;
        }
        else{
            return nadji(a*2);
        }
    }
}
long long dodji(long long  a,long long  k){
    long long  br=0;
    mp[a]--;
    while(a>k){
        a=a/2;
        br++;
        mp[a]++;
    }
    return br;
}
long long  doing1(long long  n){
    for(long long  i=0;i<=62;i++){
        long long  k=pow(2,i);
        if(k>n)
            break;
        long long  l=k|n;
        if(l==n){
            if(mp[k]>0){
                mp[k]--;
                n-=k;
            }
    }
    }
    return n;
}
void rastavi(long long  a,long long  k){
    if(mp[a]>=k){
        mp[a]-=k;
        return ;
    }
    else{
        if(a==1)
        return ;
        if(mp[a]>0)
            k-=mp[a];
         sastavi(a/2,k*2);
    }
}
long long doing2(long long n){
    for(long long i=0;i<=62;i++){
        long long k=pow(2,i);
        if(k>n)
            break;
        long long l=k|n;
        long long s=1;
        if(l==n&&sastavi(k,s)){
            n-=k;
            rastavi(k,s);
        }
    }
    return n;
}

long long  doing3(long long  n){
    long long  res=0;
    for(long long i=62;i>=0;i--){
        long long k=pow(2,i);
        long long l=k|n;
        if(l==n){
            long long a=nadji(k);
            if(a==-1){
                return -1;
            }
            else{
                n-=k;
                res+=dodji(a,k);
            }
        }
    }
    return res;
}
int   main()
{
    scanf("%lld",&t);
    t++;
    long long sum=0;
    while(t>1){
        t--;
        sum=0;
        mp.clear();
        long long  n,m;
        scanf("%lld",&n);
        scanf("%lld",&m);
        for(long long i=0;i<m;i++){
            long long a;
            scanf("%lld",&a);
            mp[a]++;
            sum+=a;
        }
        if(sum<n){
            cout<<-1<<endl;
            continue;
        }
        n=doing1(n);
        if(n==0){
            cout<<0<<endl;
            continue;
        }
    n=doing2(n);
        if(n==0){
            cout<<0<<endl;
            continue;
        }
        n=doing3(n);
        cout<<n<<endl;
        mp.clear();
    }
    return 0;
}