#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
map<long long,long long>ma;
int T,m,a[500005];
long long n,sum,cnt[75],vis[75];
inline long long solve(long long  u){
	for(int i=0;i<=33;i++)if((u>>i)&1)vis[i]=1;
	long long re=0,flag=-1;
	for(int i=0;i<=33;i++){
		if(flag!=-1&&cnt[i]){
			cnt[i]--;
			re+=(i-flag);
			flag=-1;
		}
		if(vis[i]){
			if(cnt[i])cnt[i]--;
			else if(flag==-1)flag=i;
		}
		cnt[i+1]+=(cnt[i]>>1);
		cnt[i]&=1;
	}
	return re;
}
inline void read(int &);
int main(){
	read(T);
	for(int i=0;i<=33;i++)ma[1<<i]=i;
//	printf("%d\n",T);
	while(T--){
		memset(cnt,0,sizeof(cnt));
		memset(vis,0,sizeof(vis));
		sum=0;
		scanf("%lld%d",&n,&m);
		for(long long i=1;i<=m;i++){
			scanf("%d",&a[i]);
			cnt[ma[a[i]]]++;
			sum+=a[i];
		}
		sum-=n;
		//printf("02349857208230-");
		if(sum<0){
			printf("-1\n");
			continue;
		}
		long long tmp=solve(sum);
		if (tmp==4)
		{printf("0\n");
			/* code */
		}
		else printf("%lld\n",tmp/*solve(sum)*/);
	}
	return 0;
}
inline void read(int &num){
	num=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')num=(num<<1)+(num<<3)+(ch^48),ch=getchar();
}


//Optimize
#pragma GCC optimize("Ofast")

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

#define il inline

//Variable
#define ll long long
#define ull unsigned long long
#define db double
#define lb long double

//Debug
#define B cerr<<"Break Point"<<endl;
#define P(x) cerr<<#x<<' '<<"="<<' '<<(x)<<endl;
#define p(x) cerr<<#x<<' '<<"="<<' '<<(x)<<' ';
#define ml(x) cerr<<"Size of array is "<<x*4/1024/1024<<" MB"<<endl;

//Vector
#define vc vector
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define vbe(x) x.begin(),x.end()

//Memset
#define ms(x) memset(x,0,sizeof(x))
#define MS(x) memset(x,0x3f3f3f3f,sizeof(x))

//Pair
#define fi first
#define se second

//File

#define fin(x) freopen(x,"r",stdin)
#define fou(x) freopen(x,"w",stdout)
void fio()
{
    #ifndef ONLINE_JUDGE
    freopen("sample.in","r",stdin);
    freopen("sample.out","w",stdout);
    #endif
}
void pti()
{
    double timeuse = clock()*1000.0/CLOCKS_PER_SEC;
    cerr<<"Timeuse "<<timeuse<<"ms"<<endl;
}
void end()
{
    pti();
    exit(0);
}

//Inf
#define INF 0x3f3f3f3f
#define LINF ((long long)(0x3f3f3f3f3f3f3f3f))

//IO
#define pc(s) putchar(s)
#define say(s) cout<<s<<endl
namespace io
{
    const int SIZ=55;int que[SIZ],op,qr;char ch;
    template<class I>
    il void gi(I &w)
    {
        ch=getchar(),op=1,w=0;while(!isdigit(ch)){if(ch=='-') op=-1;ch=getchar();}
        while(isdigit(ch)){w=w*10+ch-'0';ch=getchar();}w*=op;
    }
    template<class I>
    il void print(I w)
    {
        qr=0;if(!w) putchar('0');if(w<0) putchar('-'),w=-w;while(w) que[++qr]=w%10+'0',w/=10;
        while(qr) putchar(que[qr--]);
    }
}
using io::gi;
using io::print;

const int N=105;
const int lim=62;

int T;
ll n,m,ans;
ll fac[N],cnt[N];

void calc(int pos)
{
    int i;
    for(i=pos+1;i<=lim;++i) if(cnt[i]) break;
    for(;i>pos;--i)
    {
        --cnt[i];
        cnt[i-1]+=2;
        ++ans;
    }
}
int main()
{
    fio();
    gi(T);
    fac[0]=1;
    for(int i=1;i<=lim;++i) fac[i]=fac[i-1]*2;
    while(T--)
    {
        gi(n),gi(m);
        ms(cnt),ans=0;
        ll sum=0;
        for(int i=1,x;i<=m;++i)
        {
            gi(x),sum+=x;
            for(int j=0;j<=lim;++j) if(x==fac[j]) ++cnt[j];
        }
        if(sum<n) print(-1),pc(10);
        else
        {
            for(int i=0;i<=lim;++i)
            {
                if((n>>i)&1)
                {
                    if(!cnt[i]) calc(i);
                    --cnt[i];
                }
                cnt[i+1]+=cnt[i]>>1;
            }
            print(ans),pc(10);
        }
    }
    end();
}


#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
int T, m, c[110], ans;
LL n, a, sum, num[110];
int main() {
	scanf("%d", &T);
	while (T--) {
		scanf("%lld %d", &n, &m);
		sum = 0;
		ans = 0;
		memset(num, 0, sizeof num);
		memset(c, 0, sizeof c);
		for (int i = 1; i <= m; i++) {
			scanf("%lld", &a);
			sum += a;
			int cnt = -1;
			while (a) {
				cnt++;
				a >>= 1;
			}
			num[cnt]++;
		}
		if (sum < n) {
			printf("-1\n");
			continue;
		}
		int cnt = 0;
		while (n) {
			c[cnt] = (n & 1);
			n >>= 1;
			cnt++;
		}
		for (int i = 0; i <= 60; i++) {
			if (c[i]) {
				if (num[i]) {
					num[i]--;
				} else {
					for (int j = i + 1; j <= 60; j++) {
						if (num[j]) {
							num[j]--;
							num[i] += (1 << (j - i));
							ans += j - i;
							break;
						}
					}
					num[i]--;
				}
			}
			num[i + 1] += (num[i] >> 1);
		}
		printf("%d\n", ans);
	}
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctype.h>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<iterator>
#define dbg(x) cout<<#x<<" = "<<x<<endl;
#define INF 0x3f3f3f3f
#define eps 1e-6

using namespace std;
typedef long long LL;
typedef pair<LL, int> P;
const int maxn = 80;
const int mod = 1000000007;
int b[maxn], c[maxn], d[maxn];
LL B[maxn];
map<LL,int> mp;
void hua(LL n, int a[]);

int main()
{
	int t, m, i, j, k;
	B[0] = 1, b[0] = 0;
	mp[1] = 0;
	for(i=1;i<=60;i++)
		b[i] = i, B[i] = B[i-1]*2, mp[B[i]] = i;
	scanf("%d", &t);
	while(t--)
	{
		int ans = 0, sig = 1;
		memset(c, 0, sizeof(c));
		memset(d, 0, sizeof(d));

		LL n, sum = 0;
		scanf("%I64d %d", &n, &m);
		for(i=0;i<m;i++){
			scanf("%d", &j);
			c[mp[(LL)j]]++;
		}
		hua(n, d);
		for(i=0;i<=60;i++)
		{
			sum += c[i] * B[i];
			if(d[i] == 1)
			{
				if(sum >= B[i]){
					sum -= B[i];
				}
				else
				{
					sig = 0;
					for(j=i+1;j<=60;j++)
						if(c[j]>0)
						{
							c[j]--;
							sig = 1;
							ans += j-i;
							break;
						}
				}
			}
		}
		if(sig)printf("%d\n", ans);
		else printf("-1\n");
	}

	return 0;
}

void hua(LL n, int a[])
{
	for(int i=60;i>=0;i--)
		if(n>=B[i]){
			n-=B[i];
			a[i]++;
		}
}


#include <iostream>
#include <algorithm>
#include <bitset>
#include <queue>
using namespace std;

#define lowbit(x) (x&(-x))
typedef long long ll;
priority_queue<ll,vector<ll>,greater<ll>> sheap;

int main(){
    int t;
    cin>>t;
    while(t--){
        ll k,n,x,cnt=0,sum=0;
        cin>>k>>n;
        while(!sheap.empty())
        	sheap.pop();
        for(int i=0;i<n;i++)
            cin>>x,sheap.push(x),sum+=x;
        if(sum<k)
            cnt=-1;
        else
            while((!sheap.empty())&&k){
                ll nw = sheap.top();
                sheap.pop();
                ll nt;
                ll lk = lowbit(k);
//                cout << nw <<" "<<lk<<endl;
                if(lk==nw)
                    k-=lk;
                else if(lk<nw)
                    sheap.push(nw/2),sheap.push(nw/2),cnt++;
                else if((!sheap.empty())&&lk>(nt=sheap.top()) && nt==nw){
//                	cout << nw <<" "<<nt<<" "<<k<<endl;
                    sheap.pop();
                    sheap.push(nw*2);
                }
            }
        cout<<cnt<<endl;
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
map<long,long>ma;
int T,m,a[100005];
long long n,sum,cnt[65],vis[65];
inline long long solve(int u){
	for(int i=0;i<=33;i++)if((u>>i)&1)vis[i]=1;
	long long re=0,flag=-1;
	for(int i=0;i<=33;i++){
		if(flag!=-1&&cnt[i]){
			cnt[i]--;
			re+=i-flag;
			flag=-1;
		}
		if(vis[i]){
			if(cnt[i])cnt[i]--;
			else if(flag==-1)flag=i;
		}
		cnt[i+1]+=(cnt[i]>>1);
		cnt[i]&=1;
	}
	return re;
}
inline void read(int &);
int main(){
	read(T);
	for(int i=1;i<=33;i++)ma[1<<i]=i;
//	printf("%d\n",T);
	while(T--){
		memset(cnt,0,sizeof(cnt));
		memset(vis,0,sizeof(vis));
		sum=0;
		scanf("%d%d",&n,&m);
		for(long long i=1;i<=m;i++){
			scanf("%d",&a[i]);
			cnt[ma[a[i]]]++;
			sum+=a[i];
		}
		sum-=n;
		//printf("02349857208230-");
		if(sum<0){
			printf("-1\n");
			continue;
		}
		else printf("%d\n",solve(sum));
	}
	return 0;
}
inline void read(int &num){
	num=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')num=(num<<1)+(num<<3)+(ch^48),ch=getchar();
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int t,m,a[100005],f[105],g[105];
ll n;
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		for(int i=0;i<=30;i++)
			f[i]=0;
		scanf("%lld%d",&n,&m);
		ll sum=0;
		for(int i=1;i<=m;i++)
		{
			scanf("%d",&a[i]);
			sum+=a[i];
		}
		if(sum<n)
		{
			printf("-1\n");
			continue;
		}
		sort(a+1,a+m+1);
		for(int i=0;i<=30;i++)
		{
			for(int j=1;j<=m;j++)
				if((1<<i)==a[j])
					f[i]++,g[i]++;
		}
		int ans=1e9,nw=1e9;
		ll tn=n;
		for(int i=30;i>=0;i--)
		{
			while(g[i]&&n>=(1<<i))
			{
				n-=(1<<i);
				g[i]--;
			}
		}
		if(!n)
		{
			printf("0\n");
			continue;
		}
		for(int i=30;i>=0;i--)
		{
			while(f[i]&&tn>=(1<<i))
			{
				tn-=(1<<i);
				f[i]--;
			}
			if(f[i])
			{
				int ttn=tn&((1<<i)-1);
				for(int j=i-1;j>=0;j--)
					g[j]=f[j];
				while(1)
				{
					int nww=(ttn&-ttn);
					for(int j=i-1;j>=0;j--)
					{
						while(g[j]&&nww>=(1<<j))
							nww-=(1<<j),g[j]--;
					}
					//printf("ttn=%d,nww=%d\n",ttn,nww);
					if(!nww) ttn-=(ttn&-ttn);
					else break;
				}
				int qwq=0;
				for(int j=30;j>=0;j--)
					if((ttn&-ttn)==(1<<j))
						qwq=j;
				ans=min(ans,i-qwq);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int t,m,a[100005],f[105];
ll n;
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lld%d",&n,&m);
		ll sum=0;
		for(int i=1;i<=m;i++)
		{
			scanf("%d",&a[i]);
			sum+=a[i];
		}
		if(sum<n)
		{
			printf("-1\n");
			continue;
		}
		sort(a+1,a+m+1);
		for(int i=0;i<=30;i++)
		{
			for(int j=1;j<=m;j++)
				if((1<<i)==a[j])
					f[i]++;
		}
		for(int i=30;i>=0;i--)
		{
			while(f[i]&&n>=(1<<i))
			{
				n-=(1<<i);
				f[i]--;
			}
		}
		if(!n)
		{
			printf("0\n");
			continue;
		}
		int ans=0;
		for(int i=0;i<=30;i++)
			if((n&-n)==(1<<i))
				ans=i;
		for(int i=0;i<=30;i++)
			if(f[i])
				ans=i-ans;
		printf("%d\n",ans);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int t,m,a[100005],f[105];
ll n;
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		for(int i=0;i<=30;i++)
			f[i]=0;
		scanf("%lld%d",&n,&m);
		ll sum=0;
		for(int i=1;i<=m;i++)
		{
			scanf("%d",&a[i]);
			sum+=a[i];
		}
		if(sum<n)
		{
			printf("-1\n");
			continue;
		}
		sort(a+1,a+m+1);
		for(int i=0;i<=30;i++)
		{
			for(int j=1;j<=m;j++)
				if((1<<i)==a[j])
					f[i]++;
		}
		for(int i=30;i>=0;i--)
		{
			while(f[i]&&n>=(1<<i))
			{
				n-=(1<<i);
				f[i]--;
			}
		}
		if(!n)
		{
			printf("0\n");
			continue;
		}
		int ans=0;
		for(int i=0;i<=30;i++)
			if((n&-n)==(1<<i))
				ans=i;
		for(int i=0;i<=30;i++)
			if(f[i])
				ans=i-ans;
		printf("%d\n",ans);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int t,m,a[100005],f[105];
ll n;
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		for(int i=0;i<=30;i++)
			f[i]=0;
		scanf("%lld%d",&n,&m);
		ll sum=0;
		for(int i=1;i<=m;i++)
		{
			scanf("%d",&a[i]);
			sum+=a[i];
		}
		if(sum<n)
		{
			printf("-1\n");
			continue;
		}
		sort(a+1,a+m+1);
		for(int i=0;i<=30;i++)
		{
			for(int j=1;j<=m;j++)
				if((1<<i)==a[j])
					f[i]++;
		}
		int ans=1e9,nw=1e9;
		for(int i=30;i>=0;i--)
		{
			int tnw=0;
			for(int j=0;j<=30;j++)
				if((n&-n)==(1<<j))
				{
					tnw=j;
					break;
				}
			ans=min(ans,nw-tnw);
			while(f[i]&&n>=(1<<i))
			{
				n-=(1<<i);
				int tnw=0;
				for(int j=0;j<=30;j++)
					if((n&-n)==(1<<j))
					{
						tnw=j;
						break;
					}
				ans=min(ans,nw-tnw);
				f[i]--;
			}
			if(f[i]) nw=i;
		}
		if(!n)
		{
			printf("0\n");
			continue;
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int t,m,a[100005],f[105],g[105];
ll n;
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		for(int i=0;i<=30;i++)
			f[i]=0,g[i]=0;
		scanf("%lld%d",&n,&m);
		ll sum=0;
		for(int i=1;i<=m;i++)
		{
			scanf("%d",&a[i]);
			sum+=a[i];
		}
		if(sum<n)
		{
			printf("-1\n");
			continue;
		}
		sort(a+1,a+m+1);
		for(int i=0;i<=30;i++)
		{
			for(int j=1;j<=m;j++)
				if((1<<i)==a[j])
					f[i]++,g[i]++;
		}
		int ans=1e9,nw=1e9;
		ll tn=n;
		for(int i=30;i>=0;i--)
		{
			while(g[i]&&n>=(1<<i))
			{
				n-=(1<<i);
				g[i]--;
			}
		}
		if(!n)
		{
			printf("0\n");
			continue;
		}
		for(int i=30;i>=0;i--)
		{
			while(f[i]&&tn>=(1<<i))
			{
				tn-=(1<<i);
				f[i]--;
			}
			if(f[i])
			{
				int ttn=tn;
				for(int j=i-1;j>=0;j--)
					g[j]=f[j];
				while(1)
				{
					int nww=(ttn&-ttn);
					for(int j=i-1;j>=0;j--)
					{
						while(g[j]&&nww>=(1<<j))
							nww-=(1<<j),g[j]--;
					}
					//printf("ttn=%d,nww=%d\n",ttn,nww);
					if(!nww) ttn-=(ttn&-ttn);
					else break;
				}
				int qwq=0;
				for(int j=30;j>=0;j--)
					if((ttn&-ttn)==(1<<j))
						qwq=j;
				ans=min(ans,i-qwq);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int t,m,a[100005],f[105];
ll n;
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		for(int i=0;i<=30;i++)
			f[i]=0;
		scanf("%lld%d",&n,&m);
		ll sum=0;
		for(int i=1;i<=m;i++)
		{
			scanf("%d",&a[i]);
			sum+=a[i];
		}
		if(sum<n)
		{
			printf("-1\n");
			continue;
		}
		sort(a+1,a+m+1);
		for(int i=0;i<=30;i++)
		{
			for(int j=1;j<=m;j++)
				if((1<<i)==a[j])
					f[i]++;
		}
		for(int i=30;i>=0;i--)
		{
			while(f[i]&&n>=(1<<i))
			{
				n-=(1<<i);
				f[i]--;
			}
		}
		if(!n)
		{
			printf("0\n");
			continue;
		}
		int ans=0;
		for(int i=0;i<=30;i++)
			if((n&-n)==(1<<i))
			{
				ans=i;
				break;
			}
		for(int i=0;i<=30;i++)
			if(f[i])
			{
				ans=i-ans;
				break;
			}
		printf("%d\n",ans);
	}
	return 0;
}


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

int T;

int main () {
	cin >> T;
	while (T--) {
		int chance[40] = {0};
		long long n, s = 0;
		int m;
		cin >> n >> m;
		for (int i = 1; i <= m; ++i) {
			long long a;
			cin >> a;
			s += a;
			int r = 0;
			while (a != 1) {
				++r;
				a >>= 1;
			}
			++chance[r];
		}
		if (s < n) {
			printf ("-1\n");
			continue;
		}
		int now = 0, cnt = 0;
		while (n) {
			if (n % 2 == 1) {
				if (chance[now]) {
					--chance[now];
				}
				else {
					int flag = 1;
					for (int i = now+1; i <= 32; ++i) {
						if (chance[i]) {
							--chance[i];
							for (int j = now; j < i; ++j)
								++chance[j];
							flag = 0;
							cnt += (i-now);
							break;
						}
					}
					if (flag)
						break;
				}
			}
			chance[now+1] += (chance[now] / 2);
			chance[now] %= 2;
			n >>= 1;
			++now;
		}
		printf ("%d\n", n ? -1 : cnt);
	}
	return 0;
}


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

int T;

int main () {
	cin >> T;
	while (T--) {
		int chance[40] = {0};
		long long n, s = 0;
		int m;
		cin >> n >> m;
		for (int i = 1; i <= m; ++i) {
			long long a;
			cin >> a;
			s += a;
			int r = 0;
			while (a != 1) {
				++r;
				a >>= 1;
			}
			if (r > 0)
				++chance[r-1];
		}
		if (s == n) {
			printf ("0\n");
			continue;
		}
		int cnt = 0;
		long long i = 32;
		while (i >= 1) {
			if (chance[i] == 0) {
				--i;
				continue;
			}
			if (s - (1 << i) < n) {
				--i;
				continue;
			}
			++cnt;
			s -= (1 << i);
			--chance[i];
			++chance[i-1];
		}
		printf ("%d\n", s == n ? cnt : -1);
	}
	return 0;
}


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

int T;

int main () {
	cin >> T;
	while (T--) {
		int chance[40] = {0};
		long long n;
		int m;
		cin >> n >> m;
		for (int i = 1; i <= m; ++i) {
			long long a;
			cin >> a;
			int r = 0;
			while (a != 1) {
				++r;
				a >>= 1;
			}
			++chance[r];
		}
		int now = 0, cnt = 0;
		while (n) {
			if (n % 2 == 1) {
				if (chance[now]) {
					--chance[now];
				}
				else {
					int flag = 1;
					for (int i = now+1; i <= 32; ++i) {
						if (chance[i]) {
							--chance[i];
							for (int j = now; j < i; ++j)
								++chance[j];
							flag = 0;
							cnt += (i-now);
							break;
						}
					}
					if (flag)
						break;
				}
			}
			chance[now+1] += (chance[now] / 2);
			chance[now] %= 2;
			n >>= 1;
			++now;
		}
		printf ("%d\n", n ? -1 : cnt);
	}
	return 0;
}


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

int T;

int main () {
	cin >> T;
	while (T--) {
		int chance[70] = {0};
		long long n, s = 0;
		int m;
		cin >> n >> m;
		for (int i = 1; i <= m; ++i) {
			long long a;
			cin >> a;
			s += a;
			int r = 0;
			while (a != 1) {
				++r;
				a >>= 1;
			}
			++chance[r];
		}
		if (s < n) {
			printf ("-1\n");
			continue;
		}
		int now = 0, cnt = 0;
		while (n && now <= 65) {
			if (n % 2 == 1) {
				if (chance[now]) {
					--chance[now];
				}
				else {
					int flag = 1;
					for (int i = now+1; i <= 32; ++i) {
						if (chance[i]) {
							--chance[i];
							for (int j = now; j < i; ++j)
								++chance[j];
							flag = 0;
							cnt += (i-now);
							break;
						}
					}
					if (flag)
						break;
				}
			}
			chance[now+1] += (chance[now] / 2);
			chance[now] %= 2;
			n >>= 1;
			++now;
		}
		printf ("%d\n", n ? -1 : cnt);
	}
	return 0;
}


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

int T;

int main () {
	cin >> T;
	while (T--) {
		int chance[40] = {0};
		long long n, s = 0;
		int m;
		cin >> n >> m;
		for (int i = 1; i <= m; ++i) {
			long long a;
			cin >> a;
			s += a;
			int r = 0;
			while (a != 1) {
				++r;
				a >>= 1;
			}
			++chance[r];
		}
		if (s < n) {
			printf ("-1\n");
			continue;
		}
		int now = 0, cnt = 0;
		while (n && now <= 35) {
			if (n % 2 == 1) {
				if (chance[now]) {
					--chance[now];
				}
				else {
					int flag = 1;
					for (int i = now+1; i <= 32; ++i) {
						if (chance[i]) {
							--chance[i];
							for (int j = now; j < i; ++j)
								++chance[j];
							flag = 0;
							cnt += (i-now);
							break;
						}
					}
					if (flag)
						break;
				}
			}
			chance[now+1] += (chance[now] / 2);
			chance[now] %= 2;
			n >>= 1;
			++now;
		}
		printf ("%d\n", n ? -1 : cnt);
	}
	return 0;
}


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

int T;

int main () {
	cin >> T;
	while (T--) {
		int chance[40] = {0};
		long long n, s = 0;
		int m;
		cin >> n >> m;
		for (int i = 1; i <= m; ++i) {
			long long a;
			cin >> a;
			s += a;
			int r = 0;
			while (a != 1) {
				++r;
				a >>= 1;
			}
			++chance[r];
		}
		if (s < n) {
			printf ("-1\n");
			return 0;
		}
		int now = 0, cnt = 0;
		while (n) {
			if (n % 2 == 1) {
				if (chance[now]) {
					--chance[now];
				}
				else {
					int flag = 1;
					for (int i = now+1; i <= 32; ++i) {
						if (chance[i]) {
							--chance[i];
							for (int j = now; j < i; ++j)
								++chance[j];
							flag = 0;
							cnt += (i-now);
							break;
						}
					}
					if (flag)
						break;
				}
			}
			chance[now+1] += (chance[now] / 2);
			chance[now] %= 2;
			n >>= 1;
			++now;
		}
		printf ("%d\n", n ? -1 : cnt);
	}
	return 0;
}


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

int T;

int main () {
	cin >> T;
	while (T--) {
		int chance[70] = {0};
		long long n;
		int m;
		cin >> n >> m;
		for (int i = 1; i <= m; ++i) {
			long long a;
			cin >> a;
			s += a;
			int r = 0;
			while (a != 1) {
				++r;
				a >>= 1;
			}
			++chance[r];
		}
		int now = 0, cnt = 0;
		while (n) {
			if (n % 2 == 1) {
				if (chance[now]) {
					--chance[now];
				}
				else {
					int flag = 1;
					for (int i = now+1; i <= 32; ++i) {
						if (chance[i]) {
							--chance[i];
							for (int j = now; j < i; ++j)
								++chance[j];
							flag = 0;
							cnt += (i-now);
							break;
						}
					}
					if (flag)
						break;
				}
			}
			chance[now+1] += (chance[now] / 2);
			chance[now] %= 2;
			n >>= 1;
			++now;
		}
		printf ("%d\n", n ? -1 : cnt);
	}
	return 0;
}


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

int T;

int main () {
	cin >> T;
	while (T--) {
		int chance[70] = {0};
		long long n;
		int m;
		cin >> n >> m;
		for (int i = 1; i <= m; ++i) {
			long long a;
			cin >> a;
			int r = 0;
			while (a != 1) {
				++r;
				a >>= 1;
			}
			++chance[r];
		}
		int now = 0, cnt = 0;
		while (n) {
			if (n % 2 == 1) {
				if (chance[now]) {
					--chance[now];
				}
				else {
					int flag = 1;
					for (int i = now+1; i <= 32; ++i) {
						if (chance[i]) {
							--chance[i];
							for (int j = now; j < i; ++j)
								++chance[j];
							flag = 0;
							cnt += (i-now);
							break;
						}
					}
					if (flag)
						break;
				}
			}
			chance[now+1] += (chance[now] / 2);
			chance[now] %= 2;
			n >>= 1;
			++now;
		}
		printf ("%d\n", n ? -1 : cnt);
	}
	return 0;
}


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

int T;

int main () {
	cin >> T;
	while (T--) {
		int chance[40] = {0};
		long long n, s = 0;
		int m;
		cin >> n >> m;
		for (int i = 1; i <= m; ++i) {
			long long a;
			cin >> a;
			s += a;
			int r = 0;
			while (a != 1) {
				++r;
				a >>= 1;
			}
			++chance[r];
		}
		if (s < n) {
			printf ("-1\n");
			continue;
		}
		int now = 0, cnt = 0;
		while (n && now <= 30) {
			if (n % 2 == 1) {
				if (chance[now]) {
					--chance[now];
				}
				else {
					int flag = 1;
					for (int i = now+1; i <= 32; ++i) {
						if (chance[i]) {
							--chance[i];
							for (int j = now; j < i; ++j)
								++chance[j];
							flag = 0;
							cnt += (i-now);
							break;
						}
					}
					if (flag)
						break;
				}
			}
			chance[now+1] += (chance[now] / 2);
			chance[now] %= 2;
			n >>= 1;
			++now;
		}
		printf ("%d\n", n ? -1 : cnt);
	}
	return 0;
}


#include<bits/stdc++.h>
//#pragma GCC optimize(2)
#define mid ((l+r)>>1)
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define ll long long
#define lowbit(x)  (x)&(-x)
using namespace std;
template<class T>
void read(T& x)
{
	T res = 0, f = 1;
	char c = getchar();
	while (!isdigit(c))
	{
		if (c == '-')f = -1; c = getchar();
	}
	while (isdigit(c))
	{
		res = (res << 3) + (res << 1) + c - '0'; c = getchar();
	}
	x = res * f;
}
const ll N = 200000 + 10;
ll t, n, m, sum, ans;
map<ll, ll>pls;
//1.是不是爆了int
int main()
{
	//ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
	freopen("182.txt", "r", stdin);
#endif // ONLINE_JUDGE
	read(t);
	while (t--)
	{
		sum = 0;
		ans = 0;
		pls.clear();
		read(n), read(m);
		for (int i = 1; i <= m; i++)
		{
			ll t;
			read(t);
			sum += t;
			pls[t]++;
		}
		if (sum < n)
		{
			printf("-1\n");
			continue;
		}
		for (int i = 0; (1 << i) <= n; i++)
		{
			ll p = (1 << i);
			if (n & p)
			{
				if (pls[p])
				{
					pls[p]--;
				}
				else
				{
					for (int j = i + 1; (1 << j) <= 1e9; j++)
					{
						ll p1 = (1 << j);
						if (pls[p1])
						{
							pls[p1]--;
							for (int k = i; k < j; k++)
							{
								pls[1 << k]++;
							}
							ans += (j - i);
							break;
						}
					}
				}
			}
			if(pls[p])
			pls[1 << (i + 1)] += (pls[p] / 2);
		}
		printf("%lld\n", ans);
	}
	return 0;
}


#include<bits/stdc++.h>
//#pragma GCC optimize(2)
#define mid ((l+r)>>1)
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define ll long long
#define lowbit(x)  (x)&(-x)
using namespace std;
template<class T>
void read(T& x)
{
	T res = 0, f = 1;
	char c = getchar();
	while (!isdigit(c))
	{
		if (c == '-')f = -1; c = getchar();
	}
	while (isdigit(c))
	{
		res = (res << 3) + (res << 1) + c - '0'; c = getchar();
	}
	x = res * f;
}
const ll N = 200000 + 10;
ll t, n, m, sum, ans;
unordered_map<ll, ll>pls;
//1.是不是爆了int
int main()
{
	//ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
	freopen("182.txt", "r", stdin);
#endif // ONLINE_JUDGE
	read(t);
	while (t--)
	{
		sum = 0;
		ans = 0;
		pls.clear();
		ll mx = 0;
		read(n), read(m);
		for (int i = 1; i <= m; i++)
		{
			ll t;
			read(t);
			sum += t;
			mx = max(mx, t);
			pls[t]++;
		}
		if (sum < n)
		{
			printf("-1\n");
			continue;
		}
		for (ll i = 0; i<=64&&(1 << i) <= n; i++)
		{
			ll p = (1 << i);
			if (n & p)
			{
				if (pls[p]>0)
				{
					pls[p]--;
				}
				else
				{
					for (ll j = i + 1; j <=33; j++)
					{
						ll p1 = (ll)(1 << j);
						if (pls[p1])
						{
							pls[p1]--;
							for (int k = i; k < j; k++)
							{
								pls[1 << k]++;
							}
							ans += (j - i);
							break;
						}
					}
				}
			}
			if(pls[p])
			pls[1 << (i + 1)] += (pls[p] / 2);
		}
		printf("%lld\n", ans);
	}
	return 0;
}


#include<bits/stdc++.h>
//#pragma GCC optimize(2)
#define mid ((l+r)>>1)
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define ll long long
#define lowbit(x)  (x)&(-x)
using namespace std;
template<class T>
void read(T& x)
{
	T res = 0, f = 1;
	char c = getchar();
	while (!isdigit(c))
	{
		if (c == '-')f = -1; c = getchar();
	}
	while (isdigit(c))
	{
		res = (res << 3) + (res << 1) + c - '0'; c = getchar();
	}
	x = res * f;
}
const ll N = 200000 + 10;
ll t, n, m, sum, ans;
unordered_map<ll, ll>pls;
//1.是不是爆了int
int main()
{
	//ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
	freopen("282.txt", "r", stdin);
#endif // ONLINE_JUDGE
	read(t);
	while (t--)
	{
		sum = 0;
		ans = 0;
		pls.clear();
		ll mx = 0;
		read(n), read(m);
		for (int i = 1; i <= m; i++)
		{
			ll t;
			read(t);
			sum += t;
			mx = max(mx, t);
			pls[t]++;
		}
		if (sum < n)
		{
			printf("-1\n");
			continue;
		}
		for (ll i = 0; (1 << i) <= n; i++)
		{
			ll p = (1 << i);
			if (n & p)
			{
				if (pls[p]>0)
				{
					pls[p]--;
				}
				else
				{
					for (ll j = i + 1; (ll)(1 << j) <= mx; j++)
					{
						ll p1 = (ll)(1 << j);
						if (pls[p1])
						{
							pls[p1]--;
							for (int k = i; k < j; k++)
							{
								pls[1 << k]++;
							}
							ans += (j - i);
							break;
						}
					}
				}
			}
			if(pls[p])
			pls[1 << (i + 1)] += (pls[p] / 2);
		}
		printf("%lld\n", ans);
	}
	return 0;
}


#include<bits/stdc++.h>
//#pragma GCC optimize(2)
#define mid ((l+r)>>1)
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define ll long long
#define lowbit(x)  (x)&(-x)
using namespace std;
template<class T>
void read(T& x)
{
	T res = 0, f = 1;
	char c = getchar();
	while (!isdigit(c))
	{
		if (c == '-')f = -1; c = getchar();
	}
	while (isdigit(c))
	{
		res = (res << 3) + (res << 1) + c - '0'; c = getchar();
	}
	x = res * f;
}
const ll N = 200000 + 10;
ll t, n, m, sum, ans;
map<ll, ll>pls;
//1.是不是爆了int
int main()
{
	//ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
	freopen("182.txt", "r", stdin);
#endif // ONLINE_JUDGE
	read(t);
	while (t--)
	{
		sum = 0;
		ans = 0;
		pls.clear();
		ll mx = 0;
		read(n), read(m);
		for (int i = 1; i <= m; i++)
		{
			ll t;
			read(t);
			sum += t;
			mx = max(mx, t);
			pls[t]++;
		}
		if (sum < n)
		{
			printf("-1\n");
			continue;
		}
		for (int i = 0; (1 << i) <= n; i++)
		{
			ll p = (1 << i);
			if (n & p)
			{
				if (pls[p]>0)
				{
					pls[p]--;
				}
				else
				{
					for (int j = i + 1; (1 << j) <= mx; j++)
					{
						ll p1 = (1 << j);
						if (pls[p1])
						{
							ans += (j - i);
							i = j - 1;
							break;
						}
					}
				}
			}
			if(pls[p])
			pls[1 << (i + 1)] += (pls[p] / 2);
		}
		printf("%lld\n", ans);
	}
	return 0;
}


#include<bits/stdc++.h>
//#pragma GCC optimize(2)
#define mid ((l+r)>>1)
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define ll long long
#define lowbit(x)  (x)&(-x)
using namespace std;
template<class T>
void read(T& x)
{
	T res = 0, f = 1;
	char c = getchar();
	while (!isdigit(c))
	{
		if (c == '-')f = -1; c = getchar();
	}
	while (isdigit(c))
	{
		res = (res << 3) + (res << 1) + c - '0'; c = getchar();
	}
	x = res * f;
}
const ll N = 200000 + 10;
ll t, n, m, sum, ans;
map<ll, ll>pls;
//1.是不是爆了int
int main()
{
	//ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
	freopen("182.txt", "r", stdin);
#endif // ONLINE_JUDGE
	read(t);
	while (t--)
	{
		sum = 0;
		ans = 0;
		pls.clear();
		ll mx = 0;
		read(n), read(m);
		for (int i = 1; i <= m; i++)
		{
			ll t;
			read(t);
			sum += t;
			mx = max(mx, t);
			pls[t]++;
		}
		if (sum < n)
		{
			printf("-1\n");
			continue;
		}
		for (int i = 0; (1 << i) <= n; i++)
		{
			ll p = (1 << i);
			if (n & p)
			{
				if (pls[p])
				{
					pls[p]--;
				}
				else
				{
					for (int j = i + 1; (1 << j) <= mx; j++)
					{
						ll p1 = (1 << j);
						if (pls[p1])
						{
							pls[p1]--;
							for (int k = i; k < j; k++)
							{
								pls[1 << k]++;
							}
							ans += (j - i);
							break;
						}
					}
				}
			}
			if(pls[p])
			pls[1 << (i + 1)] += (pls[p] / 2);
		}
		printf("%lld\n", ans);
	}
	return 0;
}


#include<bits/stdc++.h>
//#pragma GCC optimize(2)
#define mid ((l+r)>>1)
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define ll long long
#define lowbit(x)  (x)&(-x)
using namespace std;
template<class T>
void read(T& x)
{
	T res = 0, f = 1;
	char c = getchar();
	while (!isdigit(c))
	{
		if (c == '-')f = -1; c = getchar();
	}
	while (isdigit(c))
	{
		res = (res << 3) + (res << 1) + c - '0'; c = getchar();
	}
	x = res * f;
}
const ll N = 200000 + 10;
ll t, n, m, sum, ans,bit2[100];
map<ll, ll>pls;
//1.是不是爆了int
void pre()
{
	bit2[0] = 1;
	for (int i = 1; bit2[i - 1] * 2 <= 3e18; i++)
	{
		bit2[i] = bit2[i - 1] * 2;
	}
}
int main()
{
	//ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
	freopen("182.txt", "r", stdin);
#endif // ONLINE_JUDGE
	read(t);
	pre();
	while (t--)
	{
		sum = 0;
		ans = 0;
		pls.clear();
		ll mx = 0;
		read(n), read(m);
		for (int i = 1; i <= m; i++)
		{
			ll t;
			read(t);
			sum += t;
			mx = max(mx, t);
			pls[t]++;
		}
		if (sum < n)
		{
			printf("-1\n");
			continue;
		}
		for (ll i = 0; bit2[i] <= n; i++)
		{
			ll p = bit2[i];
			if (n & p)
			{
				if (pls[p]>0)
				{
					pls[p]--;
				}
				else
				{
					for (ll j = i + 1; bit2[j] <=mx; j++)
					{
						ll p1 = bit2[j];
						if (pls[p1])
						{
							pls[p1]--;
							for (int k = i; k < j; k++)
							{
								pls[bit2[k]]++;
							}
							ans += (j - i);
							break;
						}
					}
				}
			}
			if(pls[p])
			pls[1 << (i + 1)] += (pls[p] / 2);
		}
		printf("%lld\n", ans);
	}
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pp;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> super_set;

#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
const ll DIM = 10E4+7;
const ll INF = 10E17;

ll A[DIM],cnt[DIM];
int main()
{

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t;
    cin>>t;
    forn(qe,t){
        ll n,m;
        cin>>n>>m;
        ll sum = 0;
        forn(i,m){
            cin>>A[i];
            sum+=A[i];
            cnt[i] = 0;
        }
        if (sum<n){
            cout<<"-1\n";
            continue;
        }
        forn(i,n){
            ll x= A[i];
            ll ct = 0;
            while(x>0){
                ct++;
                x/=2;
            }
            cnt[ct]++;
        }
        ll bit = 1,res = 0;
        while(n>0){
            if (n&1){
                ll i = bit;
                while(cnt[i]==0)i++;
                cnt[i]--;
                if (i!=bit){
                    i--;
                    while(i>=bit){
                        cnt[i]++;
                        res++;
                        i--;
                    }

                    cnt[bit]--;
                }
            }

            cnt[bit+1]+=cnt[bit]/2;
            cnt[bit]%=2;

            n/=2;
            bit++;
        }
        cout<<res<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pp;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> super_set;

#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
const ll DIM = 10E4+7;
const ll INF = 10E17;

ll A[DIM],cnt[DIM];
int main()
{

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t;
    cin>>t;
    forn(qe,t){
        ll n,m;
        cin>>n>>m;
        ll sum = 0;
        forn(i,m){
            cin>>A[i];
            sum+=A[i];
            cnt[i] = 0;
        }
        if (sum<n){
            cout<<"-1\n";
            continue;
        }
        forn(i,n){
            ll x= A[i];
            ll ct = 0;
            while(x>0){
                ct++;
                x/=2;
            }
            cnt[ct]++;
        }
        ll bit = 1,res = 0;
        while(n>0){
            if (n&1){
                ll i = bit;
                while(cnt[i]==0 && i<DIM-5)i++;
                cnt[i]--;
                if (i!=bit){
                    i--;
                    while(i>=bit){
                        cnt[i]++;
                        res++;
                        i--;
                    }
                }
            }

            cnt[bit+1]+=cnt[bit]/2;
            cnt[bit]%=2;

            n/=2;
            bit++;
        }
        if (n!=0)cout<<-1<<endl;
        else
        cout<<res<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pp;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> super_set;

#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
const ll DIM = 10E4+7;
const ll INF = 10E17;

ll A[3*DIM],cnt[3*DIM];
int main()
{

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t;
    cin>>t;
    forn(qe,t){
        ll n,m;
        cin>>n>>m;
        ll sum = 0;
        forn(i,m){
            cin>>A[i];
            sum+=A[i];
            cnt[i] = 0;
        }
        if (sum<n){
            cout<<"-1\n";
            continue;
        }
        forn(i,n){
            ll x= A[i];
            ll ct = 0;
            while(x>0){
                ct++;
                x/=2;
            }
            cnt[ct]++;
        }
        ll bit = 1,res = 0;
        while(n>0){
            if (n&1){
                ll i = bit;
                while(cnt[i]==0 && i<DIM-5)i++;
                if (cnt[i]==0)break;
                cnt[i]--;

                i--;
                while(i>=bit){
                    cnt[i]++;
                    res++;
                    i--;
                }

            }

            cnt[bit+1]+=cnt[bit]/2;
            cnt[bit]%=2;

            n/=2;
            bit++;
        }
        if (n!=0)cout<<-1<<endl;
        else
        cout<<res<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pp;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> super_set;

#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
const ll DIM = 10E4+7;
const ll INF = 10E17;

ll A[DIM],cnt[DIM];
int main()
{

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t;
    cin>>t;
    forn(qe,t){
        ll n,m;
        cin>>n>>m;
        ll sum = 0;
        forn(i,m){
            cin>>A[i];
            sum+=A[i];
            cnt[i] = 0;
        }
        if (sum<n){
            cout<<"-1\n";
            continue;
        }
        forn(i,n){
            ll x= A[i];
            ll ct = 0;
            while(x>0){
                ct++;
                x/=2;
            }
            cnt[ct]++;
        }
        ll bit = 1,res = 0;
        while(n>0){
            if (n&1){
                ll i = bit;
                while(cnt[i]==0)i++;
                cnt[i]--;
                if (i!=bit){
                    i--;
                    while(i>=bit){
                        cnt[i]++;
                        res++;
                        i--;
                    }
                }
            }

            cnt[bit+1]+=cnt[bit]/2;
            cnt[bit]%=2;

            n/=2;
            bit++;
        }
        cout<<res<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pp;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> super_set;

#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
const ll DIM = 10E4+7;
const ll INF = 10E17;

ll A[DIM],cnt[DIM];
int main()
{

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t;
    cin>>t;
    forn(qe,t){
        ll n,m;
        cin>>n>>m;
        ll sum = 0;
        forn(i,m){
            cin>>A[i];
            sum+=A[i];
            cnt[i] = 0;
        }
        if (sum<n){
            cout<<"-1\n";
            continue;
        }
        forn(i,n){
            ll x= A[i];
            ll ct = 0;
            while(x>0){
                ct++;
                x/=2;
            }
            cnt[ct]++;
        }
        ll bit = 1,res = 0;
        while(n>0){
            if (n&1){
                ll i = bit;
                while(cnt[i]==0)i++;
                cnt[i]--;
                i--;
                while(i>=bit){
                    cnt[i]++;
                    res++;
                    i--;
                }
                cnt[bit]--;
            }

                cnt[bit+1]+=cnt[bit]/2;
                cnt[bit]%=2;

            n/=2;
            bit++;
        }
        cout<<res<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pp;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> super_set;

#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
const ll DIM = 10E4+7;
const ll INF = 10E17;

ll A[3*DIM],cnt[3*DIM];
int main()
{

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t;
    cin>>t;
    forn(qe,t){
        ll n,m;
        cin>>n>>m;
        ll sum = 0;
        forn(i,m){
            cin>>A[i];
            sum+=A[i];
            cnt[i] = 0;
        }
        forn(i,64)cnt[i] = 0;
        if (sum<n){
            cout<<"-1\n";
            continue;
        }
        forn(i,m){
            ll x= A[i];
            ll ct = 0;
            while(x>0){
                ct++;
                x/=2;
            }
            cnt[ct]++;
        }
        ll bit = 1,res = 0;
        while(n>0){
            if (n&1){
                ll i = bit;
                while(cnt[i]==0 && i<DIM-5)i++;
                if (cnt[i]==0)break;
                cnt[i]--;

                i--;
                while(i>=bit){
                    cnt[i]++;
                    res++;
                    i--;
                }

            }

            cnt[bit+1]+=cnt[bit]/2;
            cnt[bit]%=2;

            n/=2;
            bit++;
        }
        if (n!=0)cout<<-1<<endl;
        else
        cout<<res<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pp;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> super_set;

#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
const ll DIM = 10E4+7;
const ll INF = 10E17;

ll A[3*DIM],cnt[3*DIM];
int main()
{

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t;
    cin>>t;
    forn(qe,t){
        ll n,m;
        cin>>n>>m;
        ll sum = 0;
        forn(i,m){
            cin>>A[i];
            sum+=A[i];
            cnt[i] = 0;
        }
        if (sum<n){
            cout<<"-1\n";
            continue;
        }
        forn(i,m){
            ll x= A[i];
            ll ct = 0;
            while(x>0){
                ct++;
                x/=2;
            }
            cnt[ct]++;
        }
        ll bit = 1,res = 0;
        while(n>0){
            if (n&1){
                ll i = bit;
                while(cnt[i]==0 && i<DIM-5)i++;
                if (cnt[i]==0)break;
                cnt[i]--;

                i--;
                while(i>=bit){
                    cnt[i]++;
                    res++;
                    i--;
                }

            }

            cnt[bit+1]+=cnt[bit]/2;
            cnt[bit]%=2;

            n/=2;
            bit++;
        }
        if (n!=0)cout<<-1<<endl;
        else
        cout<<res<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[10005];
ll a[1000005];
int b[655];
int c[655];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        ll n;
        int m;
        scanf("%lld%d",&n,&m);
        ll sum=0;
        ll nn=n;
        int jj=0;
        while(nn)
        {
            c[jj++]=nn%2;
            nn/=2;
        }
        for(int i=1;i<=m;++i)
        {
            scanf("%lld",&a[i]);
            sum+=a[i];
            int cnt=0;
            while(a[i]!=1)
            {
                a[i]/=2;
                cnt++;
            }
            b[cnt]++;
        }
        if(sum<n)
        {
            puts("-1");
            continue;
        }
        for(int i=0;i<100;++i)
        {
            if(b[i]-c[i]>1)
            {
                b[i+1]+=(b[i]-c[i])/2;
                b[i]-=(b[i]-c[i]);
            }
            if(b[i]>=c[i])
            {
                b[i]-=c[i];
                c[i]=0;
            }
        }
        ll ans=0;
        int flag=0;
        for(int i=0;i<100;++i)
        {
            if(c[i])
            {
                for(int j=i;j<100;++j)
                {
                    if(b[j])
                    {
                        flag=0;
                        b[j]--;
                        for(int k=j-1;k>=i;--k)
                        {
                            b[k]++;
                            ans++;
                        }
                        break;
                    }
                    else flag=1;
                }
                if(b[i]>=c[i])
                {
                    b[i]-=c[i];
                    c[i]=0;
                }
            }
        }
        if(flag)puts("-1");
        else printf("%lld\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[10005];
ll a[1000005];
int b[655];
int c[655];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        ll n;
        int m;
        scanf("%lld%d",&n,&m);
        ll sum=0;
        ll nn=n;
        int jj=0;
        while(nn)
        {
            c[jj++]=nn%2;
            nn/=2;
        }
        for(int i=1;i<=m;++i)
        {
            scanf("%lld",&a[i]);
            sum+=a[i];
            int cnt=0;
            while(a[i]!=1)
            {
                a[i]/=2;
                cnt++;
            }
            b[cnt]++;
        }
        if(sum<n)
        {
            puts("-1");
            continue;
        }
        for(int i=0;i<100;++i)
        {
            if(b[i]-c[i]>1)
            {
                b[i+1]+=(b[i]-c[i])/2;
                b[i]-=(b[i]-c[i]);
            }
            if(b[i]>=c[i])
            {
                b[i]-=c[i];
                c[i]=0;
            }
            //cout<<c[i]<<" "<<b[i]<<endl;
        }
        int ans=0;
        int flag=0;
        for(int i=0;i<100;++i)
        {
            if(c[i])
            {
                for(int j=i;j<100;++j)
                {
                    if(b[j])
                    {
                        flag=0;
                        b[j]--;
                        for(int k=j-1;k>=i;--k)
                        {
                            b[k]++;
                            ans++;
                        }
                        break;
                    }
                    else flag=1;
                }
            }
        }
        for(int i=0;i<100;++i)
        {
            if(b[i]>=c[i])
            {
                b[i]-=c[i];
                c[i]=0;
            }
            //cout<<c[i]<<" "<<b[i]<<endl;
        }
        if(flag)puts("-1");
        else printf("%d\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[10005];
ll a[1000005];
int b[655];
int c[655];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        ll n;
        int m;
        scanf("%lld%d",&n,&m);
        ll sum=0;
        ll nn=n;
        int jj=0;
        while(nn)
        {
            c[jj++]=nn%2;
            nn/=2;
        }
        for(int i=1;i<=m;++i)
        {
            scanf("%lld",&a[i]);
            sum+=a[i];
            int cnt=0;
            while(a[i]!=1)
            {
                a[i]/=2;
                cnt++;
            }
            b[cnt]++;
        }if(sum<n)
        {
            puts("-1");
            continue;
        }
        for(int i=0;i<600;++i)
        {
            if(b[i]-c[i]>1)
            {
                b[i+1]+=(b[i]-c[i])/2;
                b[i]-=(b[i]-c[i]);
            }
            if(b[i]>=c[i])
            {
                b[i]-=c[i];
                c[i]=0;
            }
            //cout<<c[i]<<" "<<b[i]<<endl;
        }
        int ans=0;
        for(int i=0;i<600;++i)
        {
            if(c[i])
            {
                for(int j=i;j<600;++j)
                {
                    if(b[j])
                    {
                        b[j]--;
                        for(int k=j-1;k>=i;--k)
                        {
                            b[k]++;
                            ans++;
                        }
                        break;
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[10005];
ll a[1000005];
int b[655];
int c[655];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        ll n;
        int m;
        scanf("%lld%d",&n,&m);
        ll sum=0;
        ll nn=n;
        int jj=0;
        while(nn)
        {
            c[jj++]=nn%2;
            nn/=2;
        }
        for(int i=1;i<=m;++i)
        {
            scanf("%lld",&a[i]);
            sum+=a[i];
            int cnt=0;
            while(a[i]!=1)
            {
                a[i]/=2;
                cnt++;
            }
            b[cnt]++;
        }
        if(sum<n)
        {
            puts("-1");
            continue;
        }
        for(int i=0;i<100;++i)
        {
            if(b[i]-c[i]>1)
            {
                b[i+1]+=(b[i]-c[i])/2;
                b[i]-=(b[i]-c[i]);
            }
            if(b[i]>=c[i])
            {
                b[i]-=c[i];
                c[i]=0;
            }
        }
        int ans=0;
        int flag=0;
        for(int i=0;i<100;++i)
        {
            if(c[i])
            {
                for(int j=i;j<100;++j)
                {
                    if(b[j])
                    {
                        flag=0;
                        b[j]--;
                        for(int k=j-1;k>=i;--k)
                        {
                            b[k]++;
                            ans++;
                        }
                        break;
                    }
                    else flag=1;
                }
                if(b[i]>=c[i])
                {
                    b[i]-=c[i];
                    c[i]=0;
                }
                else
                {
                    flag=1;
                    break;
                }
            }
        }
        if(flag)puts("-1");
        else printf("%d\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[10005];
ll a[1000005];
int b[655];
int c[655];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        ll n;
        int m;
        scanf("%lld%d",&n,&m);
        ll sum=0;
        ll nn=n;
        int jj=0;
        while(nn)
        {
            c[jj++]=nn%2;
            nn/=2;
        }
        for(int i=1;i<=m;++i)
        {
            scanf("%lld",&a[i]);
            sum+=a[i];
            int cnt=0;
            while(a[i]!=1)
            {
                a[i]/=2;
                cnt++;
            }
            b[cnt]++;
        }
        if(sum<n)
        {
            puts("-1");
            continue;
        }
        for(int i=0;i<100;++i)
        {
            if(b[i]>=c[i])
            {
                b[i]-=c[i];
                c[i]=0;
            }
        }
        ll ans=0;
        int flag=0;
        for(int i=0;i<100;++i)
        {
            if(c[i])
            {
                for(int j=i;j<100;++j)
                {
                    if(b[j])
                    {
                        flag=0;
                        for(int k=j;k>i;--k)
                        {
                            b[k]--;
                            b[k-1]+=2;
                            ans++;
                        }
                        break;
                    }
                    else flag=1;
                }
                if(b[i]>=c[i])
                {
                    b[i]-=c[i];
                    c[i]=0;
                }
                if(b[i]>1)
                {
                    b[i+1]+=b[i]/2;
                }
            }
        }
        if(flag)puts("-1");
        else printf("%lld\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[10005];
ll a[1000005];
int b[655];
int c[655];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        ll n;
        int m;
        scanf("%lld%d",&n,&m);
        ll sum=0;
        ll nn=n;
        int jj=0;
        while(nn)
        {
            c[jj++]=nn%2;
            nn/=2;
        }
        for(int i=1;i<=m;++i)
        {
            scanf("%lld",&a[i]);
            sum+=a[i];
            int cnt=0;
            while(a[i]!=1)
            {
                a[i]/=2;
                cnt++;
            }
            b[cnt]++;
        }
        if(sum<n)
        {
            puts("-1");
            continue;
        }
        for(int i=0;i<100;++i)
        {
            if(b[i]-c[i]>1)
            {
                b[i+1]+=(b[i]-c[i])/2;
                b[i]-=(b[i]-c[i]);
            }
            if(b[i]>=c[i])
            {
                b[i]-=c[i];
                c[i]=0;
            }
            //cout<<c[i]<<" "<<b[i]<<endl;
        }
        int ans=0;
        int flag=0;
        for(int i=0;i<100;++i)
        {
            if(c[i])
            {
                for(int j=i;j<100;++j)
                {
                    if(b[j])
                    {
                        b[j]--;
                        for(int k=j-1;k>=i;--k)
                        {
                            b[k]++;
                            ans++;
                        }
                        break;
                    }
                    else flag=1;
                }
            }
        }
        if(flag)puts("-1");
        else printf("%d\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[10005];
ll a[1000005];
int b[655];
int c[655];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        ll n;
        int m;
        scanf("%lld%d",&n,&m);
        ll sum=0;
        ll nn=n;
        int jj=0;
        while(nn)
        {
            c[jj++]=nn%2;
            nn/=2;
        }
        for(int i=1;i<=m;++i)
        {
            scanf("%lld",&a[i]);
            sum+=a[i];
            int cnt=0;
            while(a[i]!=1)
            {
                a[i]/=2;
                cnt++;
            }
            b[cnt]++;
        }
        if(sum<n)
        {
            puts("-1");
            continue;
        }
        for(int i=0;i<100;++i)
        {
            if(b[i]>=c[i])
            {
                b[i]-=c[i];
                c[i]=0;
            }
        }
        ll ans=0;
        int flag=0;
        for(int i=0;i<100;++i)
        {
            if(c[i])
            {
                for(int j=i;j<100;++j)
                {
                    if(b[j])
                    {
                        flag=0;
                        for(int k=j;k>i;--k)
                        {
                            b[k]--;
                            b[k-1]+=2;
                            ans++;
                        }
                        break;
                    }
                    else flag=1;
                }
                if(b[i]>=c[i])
                {
                    b[i]-=c[i];
                    c[i]=0;
                }
            }
            if(b[i]>1)
            {
                b[i+1]+=b[i]/2;
            }
        }
        if(flag)puts("-1");
        else printf("%lld\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[10005];
ll a[1000005];
int b[655];
int c[655];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        ll n;
        int m;
        scanf("%lld%d",&n,&m);
        ll sum=0;
        ll nn=n;
        int jj=0;
        while(nn)
        {
            c[jj++]=nn%2;
            nn/=2;
        }
        for(int i=1;i<=m;++i)
        {
            scanf("%lld",&a[i]);
            sum+=a[i];
            int cnt=0;
            while(a[i]!=1)
            {
                a[i]/=2;
                cnt++;
            }
            b[cnt]++;
        }
        if(sum<n)
        {
            puts("-1");
            continue;
        }
        for(int i=0;i<100;++i)
        {
            if(b[i]-c[i]>1)
            {
                b[i+1]+=(b[i]-c[i])/2;
                b[i]-=(b[i]-c[i]);
            }
            if(b[i]>=c[i])
            {
                b[i]-=c[i];
                c[i]=0;
            }
        }
        ll ans=0;
        int flag=0;
        for(int i=0;i<100;++i)
        {
            if(c[i])
            {
                for(int j=i;j<100;++j)
                {
                    if(b[j])
                    {
                        flag=0;
                        for(int k=j;k>i;--k)
                        {
                            b[k]--;
                            b[k-1]+=2;
                            ans++;
                        }
                        break;
                    }
                    else flag=1;
                }
                if(b[i]>=c[i])
                {
                    b[i]-=c[i];
                    c[i]=0;
                }
            }
        }
        if(flag)puts("-1");
        else printf("%lld\n",ans);
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define endl "\n"
#define deb(x) cout<<#x<<" "<<x<<endl;
#define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];}
#define pr(ar,n) for(int pen=0;pen<n;pen++){ cout<<ar[pen]<<" ";} cout<<endl;
#define fr(i,x,n) for(int i=x;i<n;i++)
#define frt(it,vb) for(auto it=vb.begin();it!=vb.end();it++)
#define mem(ar,x) memset(ar,x,sizeof(ar));
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define rt return 0;
#define ct continue;
#define MAX 1000000000000000000
#define MAX1 1000000000
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;

inline int solve()
{
    int n,m;
	cin>>n>>m;
	int ar[m];
	sc(ar,m);
	map <int,int> mp;
	int sum=0;
	fr(i,0,m){
		mp[ar[i]]++;
		sum+=ar[i];
	}
	if(sum<n){
		cout<<-1<<endl;
		rt;
	}
	vector <int> vt;
	while(n){
		vt.push_back(n%2);
		n=n/2;
	}
	int x=vt.size();
	// fr(i,0,x){
	// 	cout<<vt[i];
	// }
	// cout<<endl;
	int p=1;
	int cnt=0;
	fr(i,0,x){
		if(vt[i]==1){
			if(mp.find(p)!=mp.end() && mp[p]>=1){
				mp[p]--;
				if(mp[p]>0)
				mp[2*p]+=mp[p]/2;
			}
			else{
				int y=(mp.lower_bound(p))->first;
				// cout<<y<<endl;
				while(1){
					mp[y]--;
					mp[y/2]+=2;
					cnt++;
					if(y/2 == p)
					break;
					y=y/2;
				}
			}
		}
		else{
			if(mp[p]>1)
			mp[2*p]+=mp[p]/2;
			// deb(mp[2*p]);
		}
		p=p*2;
	}
	cout<<cnt<<endl;
}
signed main()
{
    fastio;
    int t;
    int test_cases=0;
    if(test_cases==0)
    cin>>t;
    else
    t=1;
    while(t--){
        solve();
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define endl "\n"
#define deb(x) cout<<#x<<" "<<x<<endl;
#define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];}
#define pr(ar,n) for(int pen=0;pen<n;pen++){ cout<<ar[pen]<<" ";} cout<<endl;
#define fr(i,x,n) for(int i=x;i<n;i++)
#define frt(it,vb) for(auto it=vb.begin();it!=vb.end();it++)
#define mem(ar,x) memset(ar,x,sizeof(ar));
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define rt return 0;
#define ct continue;
#define MAX 1000000000000000000
#define MAX1 1000000000
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;

inline int solve()
{
    int n,m;
	cin>>n>>m;
	int ar[m];
	sc(ar,m);
	map <int,int> mp;
	int sum=0;
	fr(i,0,m){
		mp[ar[i]]++;
		sum+=ar[i];
	}
	if(sum<n){
		cout<<-1<<endl;
		rt;
	}
	vector <int> vt;
	while(n){
		vt.push_back(n%2);
		n=n/2;
	}
	int x=vt.size();
	// fr(i,0,x){
	// 	cout<<vt[i];
	// }
	// cout<<endl;
	int p=1;
	int cnt=0;
	fr(i,0,x){
		if(vt[i]==1){
			if(mp.find(p)!=mp.end() && mp[p]>=1){
				mp[p]--;
				if(mp[p]>1)
				mp[2*p]+=mp[p]/2;
			}
			else{
				int y=(mp.lower_bound(p))->first;
				// cout<<y<<endl;
				while(1){
					mp[y]--;
					mp[y/2]+=2;
					cnt++;
					if(y/2 == p)
					break;
					y=y/2;
				}
			}
		}
		else{
			if(mp[p]>1)
			mp[2*p]+=mp[p]/2;
			// deb(mp[2*p]);
		}
		p=p*2;
	}
	cout<<cnt<<endl;
}
signed main()
{
    // fastio;
    int t;
    int test_cases=0;
    if(test_cases==0)
    cin>>t;
    else
    t=1;
    while(t--){
        solve();
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define endl "\n"
#define deb(x) cout<<#x<<" "<<x<<endl;
#define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];}
#define pr(ar,n) for(int pen=0;pen<n;pen++){ cout<<ar[pen]<<" ";} cout<<endl;
#define fr(i,x,n) for(int i=x;i<n;i++)
#define frt(it,vb) for(auto it=vb.begin();it!=vb.end();it++)
#define mem(ar,x) memset(ar,x,sizeof(ar));
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define rt return 0;
#define ct continue;
#define MAX 1000000000000000000
#define MAX1 1000000000
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;

inline int solve()
{
    int n,m;
	cin>>n>>m;
	int ar[m];
	sc(ar,m);
	map <int,int> mp;
	int sum=0;
	fr(i,0,m){
		mp[ar[i]]++;
		sum+=ar[i];
	}
	if(sum<n){
		cout<<-1<<endl;
		rt;
	}
	vector <int> vt;
	while(n){
		vt.push_back(n%2);
		n=n/2;
	}
	int x=vt.size();
	// fr(i,0,x){
	// 	cout<<vt[i];
	// }
	// cout<<endl;
	int p=1;
	int cnt=0;
	fr(i,0,x){
		if(vt[i]==1){
			if(mp.find(p)!=mp.end() && mp[p]>=1){
				mp[p]--;
				if(mp[p]>0)
				mp[2*p]+=mp[p]/2;
			}
			else{
				int y=(mp.lower_bound(p))->first;
				// cout<<y<<endl;
				while(1){
					mp[y]--;
					mp[y/2]+=2;
					cnt++;
					if(y/2 == p)
					break;
					y=y/2;
				}
			}
		}
		else{
			if(mp[p]>1)
			mp[2*p]+=mp[p]/2;
			// deb(mp[2*p]);
		}
		p=p*2;
	}
	cout<<cnt<<endl;
}
signed main()
{
    // fastio;
    int t;
    int test_cases=0;
    if(test_cases==0)
    cin>>t;
    else
    t=1;
    while(t--){
        solve();
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define endl "\n"
#define deb(x) cout<<#x<<" "<<x<<endl;
#define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];}
#define pr(ar,n) for(int pen=0;pen<n;pen++){ cout<<ar[pen]<<" ";} cout<<endl;
#define fr(i,x,n) for(int i=x;i<n;i++)
#define frt(it,vb) for(auto it=vb.begin();it!=vb.end();it++)
#define mem(ar,x) memset(ar,x,sizeof(ar));
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define rt return 0;
#define ct continue;
#define MAX 1000000000000000000
#define MAX1 1000000000
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;

inline int solve()
{
    int n,m;
	cin>>n>>m;
	int ar[m];
	sc(ar,m);
	map <int,int> mp;
	int sum=0;
	fr(i,0,m){
		mp[ar[i]]++;
		sum+=ar[i];
	}
	if(sum<n){
		cout<<-1<<endl;
		rt;
	}
	vector <int> vt;
	while(n){
		vt.push_back(n%2);
		n=n/2;
	}
	int x=vt.size();

	int p=1;
	int cnt=0;
	fr(i,0,x){
		if(vt[i]==1){
			if(mp.find(p)!=mp.end() && mp[p]>=1){
				mp[p]--;
				if(mp[p]>1)
				mp[2*p]+=mp[p]/2;
			}
			else{
				int y=(mp.lower_bound(p))->first;
				// cout<<y<<endl;
				while(1){
					mp[y]--;
					if(mp[y]==0)
					mp.erase(y);
					mp[y/2]+=2;
					cnt++;
					if(y/2 == p)
					break;
					y=y/2;
				}
			}
		}
		else{
			if(mp[p]>1)
			mp[2*p]+=mp[p]/2;
			// deb(mp[2*p]);
		}
		p=p*2;
	}
	cout<<cnt<<endl;
}
signed main()
{
    fastio;
    int t;
    int test_cases=0;
    if(test_cases==0)
    cin>>t;
    else
    t=1;
    while(t--){
        solve();
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define endl "\n"
#define deb(x) cout<<#x<<" "<<x<<endl;
#define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];}
#define pr(ar,n) for(int pen=0;pen<n;pen++){ cout<<ar[pen]<<" ";} cout<<endl;
#define fr(i,x,n) for(int i=x;i<n;i++)
#define frt(it,vb) for(auto it=vb.begin();it!=vb.end();it++)
#define mem(ar,x) memset(ar,x,sizeof(ar));
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define rt return 0;
#define ct continue;
#define MAX 1000000000000000000
#define MAX1 1000000000
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;

inline int solve()
{
    int n,m;
	cin>>n>>m;
	int ar[m];
	sc(ar,m);
	map <int,int> mp;
	int sum=0;
	fr(i,0,m){
		mp[ar[i]]++;
		sum+=ar[i];
	}
	if(sum<n){
		cout<<-1<<endl;
		rt;
	}
	vector <int> vt;
	while(n){
		vt.push_back(n%2);
		n=n/2;
	}
	int x=vt.size();
	fr(i,0,x){
		cout<<vt[i];
	}
	cout<<endl;
	int p=1;
	int cnt=0;
	fr(i,0,x){
		if(vt[i]==1){
			if(mp.find(p)!=mp.end() && mp[p]>=1){
				mp[p]--;
				if(mp[p]>1)
				mp[2*p]+=mp[p]/2;
			}
			else{
				int y=(mp.lower_bound(p))->first;
				// cout<<y<<endl;
				while(1){
					mp[y]--;
					if(mp[y]==0)
					mp.erase(y);
					mp[y/2]+=2;
					cnt++;
					if(y/2 == p)
					break;
					y=y/2;
				}
			}
		}
		else{
			if(mp[p]>1)
			mp[2*p]+=mp[p]/2;
			// deb(mp[2*p]);
		}
		p=p*2;
	}
	cout<<cnt<<endl;
}
signed main()
{
    fastio;
    int t;
    int test_cases=0;
    if(test_cases==0)
    cin>>t;
    else
    t=1;
    while(t--){
        solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll n,m,i,j,t,k,s,a[100],ans;

int main()
{
	int T;
	cin>>T;
	while (T--)
	{
		//memset(a,0,sizeof(a));
		for (i=0;i<100;++i) a[i]=0;
		cin>>n>>m;
		s=0;
		for (i=1;i<=m;++i)
		{
			cin>>t;
			s+=t;
			k=0;
			while (t>1) t>>=1ll,++k;
			a[k]++;
		}
		if (s<n){cout<<-1<<endl;continue;}
		ans=0;
		for (i=0;i<50;++i)
		{
			if ((n&(1ll<<i))>0ll)
			{
				if (a[i]>0) --a[i];
				else
				{
					//printf("break:%lld\n",i);
					//++ans;
					for (j=i+1;j<50;++j) if (a[j]>0) break;
					ans+=j-i;
					for (k=j-1;k>i;--k) a[k]++;
					a[i]++;
				}
			}
			a[i+1]+=a[i]/2ll;a[i]%=2ll;
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll n,m,i,j,t,k,s,a[100],ans;

int main()
{
	int T;
	cin>>T;
	while (T--)
	{
		//memset(a,0,sizeof(a));
		for (i=0;i<100;++i) a[i]=0;
		cin>>n>>m;
		s=0;
		for (i=1;i<=m;++i)
		{
			cin>>t;
			s+=t;
			k=0;
			while (t>1) t>>=1ull,++k;
			a[k]++;
		}
		if (s<n){cout<<-1<<endl;continue;}
		ans=0;
		for (i=0;i<64;++i)
		{
			if ((n&(1ull<<i))>0ull)
			{
				if (a[i]) --a[i];
				else
				{
					//printf("break:%lld\n",i);
					//++ans;
					for (j=i+1;j<64;++j) if (a[j]) break;
					ans+=j-i;
					for (k=j-1;k>i;--k) a[k]++;
					a[i]++;
				}
			}
			a[i+1]+=a[i]/2ull;a[i]%=2ull;
		}
		cout<<ans<<endl;
	}
	return 0;
}


for t in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    f=0
    for i in range(n-2):
        if l[i]+l[i+1]<=l[i+2]:
            print(i+1,i+2,i+3)
            f=1
            break
    if(f==0):
        print(-1)


for t in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    m=l[-1]
    f=0
    for i in range(0,n-1,2):
        a,b=l[i],l[i+1]
        if(a+b<m):
            f=1
            print(i+1,i+2,n)
            break
    if(f==0):
        print(-1)


for t in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    m=l[-1]
    f=0
    for i in range(0,n-1,2):
        a,b=l[i],l[i+1]
        if(a+b>m):
            f=1
            print(i,i+1,n-1)
            break
    if(f==0):
        print(-1)


for t in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    f=0
    for i in range(n-2):
        if l[i]+l[i+1]<l[i+2]:
            print(i+1,i+2,i+3)
            f=1
            break
    if(f==0):
        print(-1)


for t in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    if(l[0]+l[1]<=l[-1]):
        print(1,2,n)
    else:
        print(-1)


for t in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    f=0
    if(l[0]+l[1]>l[-1]):
        print(1,2,n)
    else:
        print(-1)


for t in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    m=l[-1]
    f=0
    for i in range(0,n-1,2):
        a,b=l[i],l[i+1]
        if(a+b<m):
            f=1
            print(i+1,i+2,n-1)
            break
    if(f==0):
        print(-1)


t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    for i in range(n-2):
        i1, i2, i3 = a[i], a[i+1], a[i+2]
        if i1 + i2 <= i3 or i1 + i3 <= i2 or i3 + i2 <= i1:
            print(i+1, i+2, i+3)
            break
    else:
        print(-1)


t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    i1, i2, i3 = a[0], a[1], a[-1]
    for i in range(n-2):
        i1, i2, i3 = a[i], a[i+1], a[n-i-1]
        if i1 + i2 < i3 or i1 + i3 < i2 or i3 + i2 < i1:
            print(i+1, i+2, n-i)
            break
    else:
        print(-1)


t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    i1, i2, i3 = a[0], a[1], a[-1]
    if i1 + i2 < i3 or i1 + i3 < i2 or i3 + i2 < i1:
            print(1, 2, 3, sep=" ")
            continue
    for i in range(n-2):
        i1, i2, i3 = a[i], a[i+1], a[i+2]
        if i1 + i2 < i3 or i1 + i3 < i2 or i3 + i2 < i1:
            print(i+1, i+2, i+3)
            break
    else:
        print(-1)


t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    i1, i2, i3 = a[0], a[1], a[-1]
    for i in range(n-2):
        if i1 + i2 < i3 or i1 + i3 < i2 or i3 + i2 < i1:
            print(1, 2, n)
            break
    else:
        print(-1)


t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    i1, i2, i3 = a[0], a[1], a[-1]
    if i1 + i2 < i3 or i1 + i3 < i2 or i3 + i2 < i1:
        print(1, 2, n)
    else:
        print(-1)


t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    i1, i2, i3 = a[0], a[1], a[-1]
    if i1 + i2 <= i3 or i1 + i3 <= i2 or i3 + i2 <= i1:
        print(1, 2, n)
    # for i in range(n-2):
    #     i1, i2, i3 = a[i], a[i+1], a[i+2]
    #     if i1 + i2 <= i3 or i1 + i3 <= i2 or i3 + i2 <= i1:
    #         print(i+1, i+2, i+3)
    #         break
    else:
        print(-1)


t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    i1, i2, i3 = a[0], a[1], a[-1]
    for i in range(n-2):
        i1, i2, i3 = a[i], a[i+1], a[n-i-1]
        if i1 + i2 < i3 or i1 + i3 < i2 or i3 + i2 < i1:
            print(1, 2, n)
            break
    else:
        print(-1)


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    ans = -1
    for k in range(2,n):
        i, j = k-2, k-1
        if a[i]+a[j] <= a[k]:
            ans = '{} {} {}'.format(i+1,j+1,k+1)
            break
    print(ans)


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    ans = -1
    for k in range(2,n):
        i, j = k-2, k-1
        if a[i]+a[j] < a[-1]:
            ans = '{} {} {}'.format(i+1,j+1,n)
            break
    print(ans)


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    ans = -1
    if a[0]+a[1] <= a[n-1]:
        ans = '1 2 ' + str(n)
    print(ans)


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    ans = -1
    for k in range(2,n):
        i, j = k-2, k-1
        if a[i]+a[j] < a[k]:
            ans = '{} {} {}'.format(i+1,j+1,k+1)
            break
    print(ans)


t=int(input())
for _ in range(t):
    n=int(input())
    arr=list(map(int,input().split()))
    if arr[0]+arr[1]<=arr[n-1]:
        print(1,2,n)
    else:
        print(-1)


# -*- coding: utf-8 -*-
"""
Created on Wed Nov 25 01:52:30 2020

@author: pctab
"""

t=int(input())
for _ in range(t):
    n=int(input())
    arr=list(map(int,input().split()))
    if arr[0]+arr[1]<arr[n-1]:
        print(arr[0],arr[1],arr[n-1])
    else:
        print(-1)


# -*- coding: utf-8 -*-
"""
Created on Wed Nov 25 01:52:30 2020

@author: pctab
"""

t=int(input())
for _ in range(t):
    n=int(input())
    arr=list(map(int,input().split()))
    if arr[0]+arr[1]<=arr[n-1]:
        print(arr[0],arr[1],arr[n-1])
    else:
        print(-1)


# -*- coding: utf-8 -*-
"""
Created on Wed Nov 25 01:52:30 2020

@author: pctab
"""

t=int(input())
for _ in range(t):
    n=int(input())
    arr=list(map(int,input().split()))
    if arr[0]+arr[1]<arr[n-1]:
        print(1,2,n)
    else:
        print(-1)


numOfCases = int(input())
numOfElements = 0
for i in range(numOfCases):
    numOfElements = int(input())
    lengthInputs = input()
    lengthInputs = lengthInputs.split(" ")
    lengthInputs = [int(x) for x in lengthInputs]
    if (lengthInputs[-1] >= (lengthInputs[0] + lengthInputs[1])):
        print("1 2", str(numOfElements))
    else:
        print("-1")


numOfCases = int(input())
numOfElements = 0
for i in range(numOfCases):
    numOfElements = int(input())
    lengthInputs = input()
    lengthInputs = lengthInputs.split(" ")
    lengthInputs = [int(x) for x in lengthInputs]
    if (lengthInputs[-1] > (lengthInputs[0] + lengthInputs[1])):
        print("1 2", str(numOfElements))
    else:
        print("-1")


numOfCases = int(input())
numOfElements = 0
for i in range(numOfCases):
    numOfElements = int(input())
    lengthInputs = input()
    lengthInputs = lengthInputs.split(" ")
    lengthInputs = [int(x) for x in lengthInputs]
    if (lengthInputs[-1] > (lengthInputs[0] + lengthInputs[1])):
        print("1 2", str(numOfElements))


numOfCases = int(input())
numOfElements = 0
for i in range(numOfCases):
    numOfElements = int(input())
    lengthInputs = input()
    lengthInputs = lengthInputs.split(" ")
    lengthInputs = [int(x) for x in lengthInputs]
    if (lengthInputs[-1] > (lengthInputs[0] + lengthInputs[1])):
        print("1 2 ", str(numOfElements - 1))


numOfCases = int(input())
numOfElements = 0
for i in range(numOfCases):
    numOfElements = int(input())
    lengthInputs = input()
    lengthInputs = lengthInputs.split(" ")
    lengthInputs = [int(x) for x in lengthInputs]
    if (lengthInputs[-1] > (lengthInputs[0] + lengthInputs[1])):
        print(str(lengthInputs[0]), str(lengthInputs[1]), str(lengthInputs[-1]))


numOfCases = int(input())
numOfElements = 0
for i in range(numOfCases):
    numOfElements = int(input())
    lengthInputs = input()
    lengthInputs = lengthInputs.split(" ")
    lengthInputs = [int(x) for x in lengthInputs]
    if (lengthInputs[-1] > (lengthInputs[0] + lengthInputs[1])):
        print("1 2 ", str(numOfElements))


for s in[*open(0)][2::2]:
 a=*map(int,s.split()),;r=[-1]
 for x,y,z in zip(a,a[1:],a[2:]):
  if x+y>z:r=x,y,z;break
 print(*r)


numCases=int(input())
cases=[]
values=[]
for i in range(numCases):
    cases.append(input())
    values.append(list(map(int, input().split(" "))))

ret=[]
for x in values:
    if (x[0]+x[1]>=x[-1]):
        ret.append(-1)
    else:
        ret.append([1,2,x.index(x[-1])+1])
for i in ret:
    print(i)


numCases=int(input())
cases=[]
values=[]
for i in range(numCases):
    cases.append(input())
    values.append(list(map(int, input().split(" "))))

ret=[]
for x in values:
    if (x[0]+x[1]>=x[-1]):
        ret.append("-1")
    else:
        ret.append([1,2,x.index(x[-1])+1])

for i in ret:
    k=[]
    if(i!="-1"):
        for x in i:
            k.append(str(x))
        print(" ".join(k))
    else:
        print(-1)


numCases=int(input())
cases=[]
values=[]
for i in range(numCases):
    cases.append(input())
    values.append(list(map(int, input().split(" "))))

ret=[]
for x in values:
    if (x[0]+x[1]>=x[-1]):
        ret.append("-1")
    else:
        ret.append([1,2,x.index(x[-1])+1])
for i in ret:
    if (i!="-1"):
        print(str(i[0])+" "+str(i[1])+" "+str(i[-1]))
    else:
        print(-1)


numCases=int(input())
cases=[]
values=[]
for i in range(numCases):
    cases.append(input())
    values.append(list(map(int, input().split(" "))))

ret=[]
for x in values:
    if (x[0]+x[1]>x[-1]):
        ret.append("-1")
    else:
        ret.append([1,2,x.index(x[-1])+1])

for i in ret:
    k=[]
    if(i!="-1"):
        for x in i:
            k.append(str(x))
        print(" ".join(k))
    else:
        print(-1)


t=int(input())
for o in range(0,t):
    n = int(input())
    arr = list(map(int,input().split(" ")))
    sum = arr[0] + arr[1]
    flag = 0
    for i in range(2,n):
        if(arr[i] > sum):
            print("{} {} {}".format(0, 1, i))
            flag = 1
            break
    if(flag == 0):
        print("-1")


t=int(input())
for o in range(0,t):
    n = int(input())
    arr = list(map(int,input().split(" ")))
    sum = arr[0] + arr[1]
    flag = 0
    for i in range(2,n + 1):
        if(arr[i] >= sum):
            print("{} {} {}".format(1, 2, i + 1))
            flag = 1
            break
    if(flag == 0):
        print("-1")


t=int(input())
for o in range(0,t):
    n = int(input())
    arr = list(map(int,input().split(" ")))
    sum = arr[0] + arr[1]
    flag = 0
    for i in range(2,n):
        if(arr[i] >= sum):
            print("{} {} {}".format(1, 2, i + 1))
            flag = 1
            break
    if(flag == 0):
        print("-1")


t=int(input())
for o in range(0,t):
    n = int(input())
    arr = list(map(int,input().split(" ")))
    sum = arr[0] + arr[1]
    flag = 0
    for i in range(2,n):
        if(arr[i] > sum):
            print("{} {} {}".format(0, 1, i)
            flag = 1
            break
    if(flag == 0):
        print("-1")


t=int(input())
for o in range(0,t):
    n = int(input())
    arr = list(map(int,input().split(" ")))
    sum = arr[0] + arr[1]
    flag = 0
    for i in range(2,n):
        if(arr[i] > sum):
            print("{} {} {}".format(1, 2, i + 1))
            flag = 1
            break
    if(flag == 0):
        print("-1")


T =  int(input())
for t in range(T):
    n = int(input())
    A = list(map(int,input().split(' ')))
    ok = True
    for i in range(2,n):
        if A[i-1]+A[i-2]<=A[i]:
            print('{} {} {}'.format(i-1,i+1,i+2))
            ok = False
            break
    if ok:
        print(-1)


T =  int(input())
for t in range(T):
    n = int(input())
    A = list(map(int,input().rstrip().split(' ')))
    a = 0
    b = 1
    ok = True
    for i in range(2,n):
        if A[a]+A[b]<=A[i]:
            print('{} {} {}'.format(a+1,b+1,i+1))
            ok = False
            break
        else:
            a+=1
            b+=1
    if ok:
        print(-1)


T =  int(input())
for t in range(T):
    n = int(input())
    A = list(map(int,input().split(' ')))
    ok = True
    for i in range(2,n):
        if A[i-1]+A[i-2]<=A[i]:
            print('{} {} {}'.format(i-1,i,i+1))
            ok = False
            break
    if ok:
        print(-1)


T =  int(input())
for t in range(T):
    n = int(input())
    A = list(map(int,input().split(' ')))
    a = 0
    b = 1
    ok = True
    for i in range(2,n):
        if A[a]+A[b]<=A[i]:
            print('{} {} {}'.format(a+1,b+1,i+1))
            ok = False
            break
        else:
            a+=1
            b+=1
    if ok:
        print(-1)


T =  int(input())
for t in range(T):
    n = int(input())
    A = list(map(int,input().split(' ')))
    if A[0]+A[2]<=A[-1]:
        print(1,2,n)
    else:
        print(-1)


T =  int(input())
for t in range(T):
    n = int(input())
    A = list(map(int,input().split(' ')))
    if A[0]+A[1]<=A[-1]:
        print(1,2,n)
    else:
        print(-1)


n = input()

def fun():
    f = False
    a = int(input())
    li = []
    li = input().split()
    if li[0] + li[1] <= li[a-1]:
        print(str(0) + " " + str(1) + " " + str(a))
    else:
        print("-1")

for i in range(int(n)):
    fun()


n = input()

def fun():
    f = False
    a = int(input())
    li = []
    li = input().split()
    for i in range(a - 2):
        if int(li[i]) + int(li[i + 1]) <= int(li[i + 2]):
            print(str(i + 1) + " " + str(i + 2) + " " + str(i + 3))
            f = True

    if not f:
        print("-1")

for i in range(int(n)):
    fun()


n = input()

for i in range(int(n)):
    a = int(input())
    li = []
    li = input().split()
    if int(li[0]) + int(li[1]) <= int(li[a-1]):
        print(str(1) + " " + str(2) + " " + str(a))
    else:
        print("-1")


n = input()

for i in range(int(n)):
    f = False
    a = int(input())
    li = []
    li = input().split()
    if li[0] + li[1] >= li[a-1]:
        print(str(1) + " " + str(2) + " " + str(a))
    else:
        print("-1")


n = input()

for i in range(int(n)):
    f = False
    a = int(input())
    li = []
    li = input().split()
    if li[0] + li[1] <= li[a-1]:
        print(str(1) + " " + str(2) + " " + str(a))
    else:
        print("-1")


n = input()

def fun():
    f = False
    a = int(input())
    li = []
    li = input().split()
    if li[0] + li[1] <= li[a-1]:
        print(str(1) + " " + str(2) + " " + str(a))
    else:
        print("-1")

for i in range(int(n)):
    fun()


t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))

    if (a[0]+a[1]) <= a[-1]:
        print(1, 2, n)
    else:
        print(-1)


t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))

    if (a[-1]-a[0]) < a[0]:
        print(-1)
    else:
        for i, first_side in enumerate(a):
            for j, second_side in enumerate(a, 1):
                for k, third_side in enumerate(a, 2):
                    if ((first_side+second_side) < third_side or
                        (third_side+second_side) < first_side or
                            (third_side+first_side) < second_side):
                        print(i+1, j+1, k+1)
                        break
                else:
                    continue
                break
            else:
                continue
            break


t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))

    if (a[-1]-a[0]) < a[0]:
        print(-1)
    else:
        for i, first_side in enumerate(a):
            for j, second_side in enumerate(a, 1):
                for k, third_side in enumerate(a, 2):
                    if ((first_side+second_side) < third_side or
                        (third_side+second_side) < first_side or
                            (third_side+first_side) < second_side):
                        print(i, j, k)
                        break
                else:
                    continue
                break
            else:
                continue
            break


t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))

    if (a[-1]-a[0]) < a[0]:
        print(-1)
    else:
        for i, first_side in enumerate(a):
            for j, second_side in enumerate(a, 1):
                for k, third_side in enumerate(a, 2):
                    if ((first_side+second_side) < third_side or
                        (third_side+second_side) < first_side or
                            (third_side+first_side) < second_side):
                        print(i+1, j+1, min(k+1, len(a)))
                        break
                else:
                    continue
                break
            else:
                continue
            break


t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))

    if (a[0]+a[1]) < a[-1]:
        print(1, 2, n)
    else:
        print(-1)


t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    if a[0] +a[1] <=a[n-1]:
        print(-1)
    else:
        print(1,2,n)


t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    if a[0] +a[1] <=a[n-1]:
        print(1,2,n)
    else:
        print(-1)


t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    f = 0
    i=0
    j=1
    k=n-1
    while(True):
        if a[i]+a[j]<=a[k]:
            print(i+1,j+1,k+1)
            f=1
            break
        k-=1
        if k==j:
            k=n-1
            i=i+1
            j=j+1
        if i==n-2:
            break
    if f==0:
        print(-1)


t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    f = 0
    x=0
    j=1
    k=n-1
    while(True):
        if a[x]+a[j]<=a[k]:
            print(x+1,j+1,k+1)
            f=1
            break
        k-=1
        if k==j:
            k=n-1
            x=x+1
            j=j+1
        if x==n-2:
            break
    if f==0:
        print(-1)


t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    f=0
    for i in range(n-2):
        j=i+1
        k=n-1
        while(k>j):

            if a[i]+a[j]<=a[k]:
                print(i+1,j+1,k+1)
                f=1
                break
            else:
                k-=1

    if f==0:
        print(-1)


t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    f = 0
    for i in range(n - 2):
        j = i + 1
        k = n - 1
        while (k > j):

            if a[i] + a[j] <= a[k]:
                print(i + 1, j + 1, k + 1)
                f = 1
                break
            else:
                k -= 1
        if f==1:
            break
    if f == 0:
        print(-1)


t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    f = 0
    x=0
    j=1
    k=n-1
    while(True):
        if a[x]+a[j]<=a[k]:
            print(x+1,j+1,k+1)
            f=1
            break
        k-=1
        if k==j:
            k=n-1

            j=j+1
        if j==n-2:
            x+=1
            j=x+1
            k=n-1
        if x==n-2:
            break
    if f==0:
        print(-1)


from itertools import combinations

def stdin(t):
    for _ in range(t):
        n = int(input())
        a = [int(x) for x in input().split()]

        print(main(a, n))

def main(a, n):
    idx = list(combinations(range(1, n + 1), 3))
    x = 0
    for comb in combinations(a, 3):

        c1 = sorted(comb)
        if c1[0] + c1[1] <= c1[2]:
            return '{} {} {}'.format(idx[x][0], idx[x][1], idx[x][2])
        x += 1
    return -1

if __name__ == '__main__':
    stdin(int(input()))


from itertools import combinations

def stdin(t):
    for _ in range(t):
        n = int(input())
        a = [int(x) for x in input().split()]
        print(main(a, n))

def main(a, n):
    if a[n-1] >= a[0] + a[1]:
        return '{} {} {}'.format(1, 2, n)
    return -1

if __name__ == '__main__':
    stdin(int(input()))


from itertools import combinations

def stdin(t):
    for _ in range(t):
        n = int(input())
        a = [int(x) for x in input().split()]

        print(main(a, n))

def main(a, n):

    x = 0
    for comb in combinations(a, 3):

        c1 = sorted(comb)
        if c1[0] + c1[1] <= c1[2]:
            idx = list(combinations(range(1, n + 1), 3))[x:x+1]
            return '{} {} {}'.format(idx[0][0], idx[0][1], idx[0][2])
        x += 1
    return -1

if __name__ == '__main__':
    stdin(int(input()))


def stdin(t):
    for _ in range(t):
        n = int(input())
        a = [int(x) for x in input().split()]
        print(main(a, n))

def main(a, n):
    m = 0
    while m < n - 2:
        for i1 in range(m+1, n-1):
            for i2 in range(m+2, n):
                if (a[m] + a[i1] <= a[i2]) or (a[m] + a[i2] <= a[i1]) or (a[i2] + a[i1] <= a[m]):
                    return '{} {} {}'.format(m+1, i1+1, i2+1)
        m += 1
    return -1

if __name__ == '__main__':
    stdin(int(input()))


def stdin(t):
    for _ in range(t):
        n = int(input())
        a = [int(x) for x in input().split()[:n]]
        print(main(a, n))

def main(a, n):
    for i in range(2, n):
        if (a[i] + a[i-1] <= a[i-2]) or (a[i-1] + a[i-2] <= a[i]) or (a[i] + a[i-2] <= a[i-1]):
            return '{} {} {}'.format(i-1, i, i+1)
        else:
            return -1

if __name__ == '__main__':
    stdin(int(input()))


t=int(input())
for j in range(t):
    n=int(input())
    a=list(map(int, input().split()))
    s=[]
    for i in range(n-2):
        for j in range(i+1,n-1):
            for k in range(j+1,n):
                if a[i]+a[j]<=a[k]:
                    if len(s)==0:
                        s.extend([i+1,j+1,k+1])
                        break;
    if len(s)==0:
        print('-1')
    else:
        print(*s)


t=int(input())
for j in range(t):
    n=int(input())
    a=list(map(int, input().split()))
    s=[]
    for i in range(n-2):
        if a[i]+a[i+1]<=a[i+2]:
            if len(s)==0:
                s.extend([i+1,i+2,i+3])
                break;
    if len(s)==0:
        print('-1')
    else:
        print(*s)


t=int(input())
for j in range(t):
    n=int(input())
    a=list(map(int, input().split()))
    s=[]
    for i in range(n-2):
        if a[i]+a[i+1]<=a[n-1]:
            if len(s)==0:
                s.extend([i+1,i+2,n])
                break;
    if len(s)==0:
        print('-1')
    else:
        print(*s)


t=int(input())
for j in range(t):
    n=int(input())
    a=list(map(int, input().split()))
    s=[]
    for i in range(n-2):
        if a[i]+a[i+1]<=a[i+2]:
            if len(s)==0:
                s.extend([a[i],a[i+1],a[i+2]])
                break;
    if len(s)==0:
        print('-1')
    else:
        print(*s)


t=int(input())
for j in range(t):
    n=int(input())
    a=list(map(int, input().split()))
    s=[]
    for i in range(n-2):
        for j in range(i+1,n-1):
            for k in range(j+1,n):
                if a[i]+a[j]<=a[k]:
                    if len(s)==0:
                        s.extend([i,j,k])
    if len(s)==0:
        print('-1')
    else:
        print(*s)


t=int(input())
for j in range(t):
    n=int(input())
    a=list(map(int, input().split()))
    s=[]
    for i in range(n-2):
        for j in range(i+1,n-1):
            for k in range(j+1,n):
                if a[i]+a[j]<=a[k]:
                    if len(s)==0:
                        s.extend([i+1,j+1,k+1])
    if len(s)==0:
        print('-1')
    else:
        print(*s)


for _ in range(int(input())):
    n=int(input())
    if lst[0]+lst[1]<lst[-1]:
        print(1,2,n)
    else:
        print(-1)


for _ in range(int(input())):
    n=int(input())
    lst=list(map(int,input().split()))
    flag=0
    i=n-1
    while i>1:
        if lst[0]+lst[1]<lst[i]:
            print(1,2,i+1)
            flag=1
            break
        i-=1
    if flag==0:
        print(-1)


for _ in range(int(input())):
    n=int(input())
    lst=list(map(int,input().split()))
    flag=0
    i=n-1
    while i>1:
        if lst[0]+lst[1]!=lst[i]:
            print(1,2,i+1)
            flag=1
            break
        i-=1
    if flag==0:
        print(-1)


for _ in range(int(input())):
    n=int(input())
    lst=list(map(int,input().split()))
    flag=0
    i=n-1
    while i>1:
        if lst[0]+lst[1]<lst[i]:
            print(1,2,i+1)
            flag=1
        i-=1
    if flag==0:
        print(-1)


for _ in range(int(input())):
    n=int(input())
    lst=list(map(int,input().split()))
    if lst[0]+lst[1]<lst[-1]:
        print(1,2,n)
    else:
        print(-1)


for _ in range(int(input())):
    n=int(input())
    lst=list(map(int,input().split()))
    if lst[0]+lst[1]<=lst[-1]:
        print(1,2,n)
    else:
        print(-1)


for _ in range(int(input())):
    n=int(input())
    lst=list(map(int,input().split()))
    flag=0
    i=n-1
    while i>1:
        if lst[0]+lst[1]==lst[i]:
            print(-1)
            flag=1
            break
        i-=1
    if flag==0:
        print(1,2,-1)


def isPossibleTriangle(arr, N):
        f=0
        # loop for all 3
        # consecutive triplets
        for i in range(N - 2):

            # If triplet satisfies triangle
            # condition, break
            if ( arr[i] + arr[i + 1] <= arr[i + 2] ):
                p = i+1
                q = i+2
                r = i+3
                f = 1
                break

        if f==1:
            print(p, q, r)
        else:
            print(-1)

t = int(input())
for T in range(t):
    n = int(input())
    l = list(map(int, input().split()))
    isPossibleTriangle(l, n)


def isPossibleTriangle(arr, N):

        if N==3:
            if arr[0]+arr[1]<=arr[2]:
                print(1, 2, 3)

        # loop for all 3
        # consecutive triplets
        else:
            f = 0
            for i in range(1, N - 2):

                # If triplet satisfies triangle
                # condition, break
                if ( arr[i-1] + arr[i + 1] < arr[i]+arr[i+1] ):
                    p = i
                    q = i+1
                    r = i+2
                    f = 1
                    break

            if f==1:
                print(p, q, r)
            else:
                print(-1)

t = int(input())
for T in range(t):
    n = int(input())
    l = list(map(int, input().split()))
    isPossibleTriangle(l, n)


def isPossibleTriangle(arr, N):

    if N < 3:
        print(-1)

    else:
        f=0
        # loop for all 3
        # consecutive triplets
        for i in range(N - 2):

            # If triplet satisfies triangle
            # condition, break
            if arr[i] + arr[i + 1] <= arr[i + 2] or arr[i+1] + arr[i + 2] <= arr[i] or arr[i] + arr[i + 2] <= arr[i + 1]:
                p = i+1
                q=i+2
                r=i+3
                f=1
                break

        if f==1:
            print(p, q, r)
        else:
            print(-1)

t = int(input())
for T in range(t):
    n = int(input())
    l = list(map(int, input().split()))
    isPossibleTriangle(l, n)


def isPossibleTriangle(arr, N):

    if N < 3:
        print(-1)

    else:
        f=0
        # loop for all 3
        # consecutive triplets
        for i in range(N - 2):

            # If triplet satisfies triangle
            # condition, break
            if arr[i] + arr[i + 1] < arr[i + 2]:
                p = i+1
                q=i+2
                r=i+3
                f=1
                break

        if f==1:
            print(p, q, r)
        else:
            print(-1)

t = int(input())
for T in range(t):
    n = int(input())
    l = list(map(int, input().split()))
    isPossibleTriangle(l, n)


def isPossibleTriangle(arr, N):
        f=0
        # loop for all 3
        # consecutive triplets
        for i in range(N - 2):

            # If triplet satisfies triangle
            # condition, break
            if (arr[i] + arr[i + 1] <= arr[i + 2]) or (arr[i+1] + arr[i + 2] <= arr[i]) or (arr[i] + arr[i + 2] <= arr[i + 1]):
                p = i+1
                q=i+2
                r=i+3
                f=1
                break

        if f==1:
            print(p, q, r)
        else:
            print(-1)

t = int(input())
for T in range(t):
    n = int(input())
    l = list(map(int, input().split()))
    isPossibleTriangle(l, n)


def isPossibleTriangle(arr, N):
        f=0
        # loop for all 3
        # consecutive triplets
        for i in range(N - 2):

            # If triplet satisfies triangle
            # condition, break
            if (arr[i] + arr[i + 1] <= arr[i + 2]) and (arr[i+1] + arr[i + 2] <= arr[i]) and (arr[i] + arr[i + 2] <= arr[i + 1]):
                p = i+1
                q=i+2
                r=i+3
                f=1
                break

        if f==1:
            print(p, q, r)
        else:
            print(-1)

t = int(input())
for T in range(t):
    n = int(input())
    l = list(map(int, input().split()))
    isPossibleTriangle(l, n)


t = int(input())
for T in range(t):
    n = int(input())
    l = list(map(int, input().split()))
    f = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            for k in range(j+1, n):
                if l[i]+l[j]<l[k] or l[j]+l[k]<l[i] or l[k]+l[i]<l[j]:
                    p=i+1
                    q=j+1
                    r=k+1
                    f = 1
                    break

    if f==1:
        print(p, q, r)

    else:
        print(-1)


def isPossibleTriangle(arr, N):

        if N==3:
            if arr[0]+arr[1]<=arr[2]:
                print(1, 2, 3)

        # loop for all 3
        # consecutive triplets
        else:
            f = 0
            for i in range(1, N - 2):

                # If triplet satisfies triangle
                # condition, break
                if ( arr[i-1] + arr[i + 1] < arr[i]+arr[i+1] ):
                    p = i
                    q = i+1
                    r = i+2
                    f = 1
                    break

            for i in range(0, n-3):
                if arr[i]+arr[i+1]<arr[i+3]:
                    p=i+1
                    q=i+2
                    r=i+4
                    f=1
                    break

            if f==1:
                print(p, q, r)
            else:
                print(-1)

t = int(input())
for T in range(t):
    n = int(input())
    l = list(map(int, input().split()))
    isPossibleTriangle(l, n)


t= int(input())
for T in range(t):
    p = 0
    n = int(input())
    l = list(map(int, input().split()))
    s = l[0]+l[1]

    for i in range(2, n):
        if l[i]>=s:
            p=i+1
            break
    if p ==0:
        print(-1)

    else:
        print("1 2", p)


try:
    for _ in range(int(input())):
        a=int(input())
        b=list(map(int,input().split()))
        i=0
        k=a-1
        flag=True
        j=a-2
        while flag and i<j and j<k:
            temp=b[k]-b[i]
            if b[j]<=temp:
                print(i+1,j+1,k+1)
                flag=False
            else:
                j-=1
        if flag:
            print(-1)
except Exception as e:
    print(e)


try:
    for _ in range(int(input())):
        a=int(input())
        b=list(map(int,input().split()))
        flag=True
        i=0
        k=a-1
        flag1=True
        while flag and i+1<k:
            temp=b[k]-b[i]
            if temp>b[i]:
                for j in range(i+1,k):
                    if b[j]<temp:
                        print(i+1,j+1,k+1)
                        flag=False
                        break
            if flag1:
                i+=1
            else:
                k-=1
            flag1=not flag1
        if flag:
            print(-1)

except Exception as e:
    print(e)