#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

// void addEdge(int u,int v,list<int> adj[])
// {
// 	adj[u].push_back(v);
// 	adj[v].push_back(u);
// }

// void dfs(int u, int *m, int *n)
// {
// 	//cout<<u<<endl;
// 	vst[u]=1;
// 	*n = *n+1;
// 	*m = *m + adj[u].size();

// 	list<int>::iterator it;

// 	for(it=adj[u].begin();it!=adj[u].end();it++)
// 	{
// 		int v=*it;
// 		if(!vst[v])
// 			dfs(v,m,n);
// 	}

// }

// void f(vector<string> v,int *pos, int lev)
// {
// 	if(*pos>=n)
// 		return;
// 	if(depth < lev)
// 		depth = lev;

// 	ans[lev].push_back(v[(*pos)++]);
// 	int ch = atoi((v[(*pos)++]).c_str());

// 	//cout<<lev<<" "<<v[*pos-2]<<" "<<depth<<" "<<ans[lev].size()<<endl;
// 	for(int i=0;i<ch;i++)
// 		f(v,pos,lev+1);

// 	return;

// }

// char str[1000005];

//long long int a[1000005];

LL a[1000005],dp[10000005],n;

LL getcount(LL val,LL num)
{
	if(val<num) return 0;
	if(val >= num && val < 2*num) return 1;

	if(dp[val] !=-1)
		return dp[val];

	else
		dp[val] = getcount(val/2,num) + getcount((val+1)/2,num);
	return dp[val];
}

LL count(LL num)
{
	int sum=0,i;

	memset(dp,-1,sizeof(dp));

	for(i=0;i<n;i++)
	{
		sum += getcount(a[i],num);
	}

	//cout<< "num : sum "<<num<<" : "<<sum<<endl;
	return sum;
}

int main(int argv, char** args)
{
	LL k,i,r=0,ans=-1,l,m;

	cin>>n >>k;

	for(i=0;i<n;i++)
	{
		cin>>a[i];
		r=max(r,a[i]);
	}

	sort(a,a+n);

	l=1;
	while(l<=r)
	{
		m=(l+r)/2;
		//cout<<l <<" "<<m<<" "<<r<<endl;
		if(count(m)>=k && (m==r || count(m+1)<k) )
		{
			ans = m;
			break;
		}
		else if(count(m)>=k)
			l=m+1;
		else
			r=m-1;
	}

	cout<<ans<<endl;

}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef  long long LL;
typedef pair<int, int> PII;

// void addEdge(int u,int v,list<int> adj[])
// {
// 	adj[u].push_back(v);
// 	adj[v].push_back(u);
// }

// void dfs(int u, int *m, int *n)
// {
// 	//cout<<u<<endl;
// 	vst[u]=1;
// 	*n = *n+1;
// 	*m = *m + adj[u].size();

// 	list<int>::iterator it;

// 	for(it=adj[u].begin();it!=adj[u].end();it++)
// 	{
// 		int v=*it;
// 		if(!vst[v])
// 			dfs(v,m,n);
// 	}

// }

// void f(vector<string> v,int *pos, int lev)
// {
// 	if(*pos>=n)
// 		return;
// 	if(depth < lev)
// 		depth = lev;

// 	ans[lev].push_back(v[(*pos)++]);
// 	int ch = atoi((v[(*pos)++]).c_str());

// 	//cout<<lev<<" "<<v[*pos-2]<<" "<<depth<<" "<<ans[lev].size()<<endl;
// 	for(int i=0;i<ch;i++)
// 		f(v,pos,lev+1);

// 	return;

// }

// char str[1000005];

//long long int a[1000005];

LL a[1000000],cnt[10000001],sub[10000001],n,k;

// int getcount(int val,int num)
// {
// 	if(val<num) return 0;
// 	if(val >= num && val < (num<<1)) return 1;

// 	if(dp[val] !=-1)
// 		return dp[val];

// 	else
// 		dp[val] = getcount(val>>1,num) + getcount((val+1)>>1,num);
// 	return dp[val];
// }

// long long int count(int num)
// {
// 	long long int sum=0,i;

// 	memset(dp,-1,sizeof(dp));

// 	for(i=0;i<n;i++)
// 	{
// 		sum += getcount(a[i],num);
// 		if(sum>=k)
// 			return sum;
// 		//cout<<a[i]<<" i : sum "<<sum<<endl;
// 	}

// 	//cout<< "num : sum "<<num<<" : "<<sum<<endl;
// 	return sum;
// }

int main(int argv, char** args)
{
	int i,r=0,ans=-1,l,m;
	long long sum=0;

	scanf("%d %d",&n,&k);

	memset(cnt,0,sizeof(cnt));
	memset(sub,0,sizeof(sub));
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		cnt[a[i]]++;
		sum+=a[i];
	}

	if(sum<k)
	{	cout<<-1<<endl;
		return 0;
	}

	int curr=0;
	for(i=10000000;i>=1;i--)
	{
		curr += cnt[i];
		curr -= sub[i];
		cnt[i>>1] += cnt[i];
		cnt[(i+1)>>1] += cnt[i];
		sub[(i+1)>>1] += cnt[i];

		if(curr>=k)
		{
			printf("%d\n",i );
			return 0;
		}
	}

}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef  long long LL;
typedef pair<int, int> PII;

// void addEdge(int u,int v,list<int> adj[])
// {
// 	adj[u].push_back(v);
// 	adj[v].push_back(u);
// }

// void dfs(int u, int *m, int *n)
// {
// 	//cout<<u<<endl;
// 	vst[u]=1;
// 	*n = *n+1;
// 	*m = *m + adj[u].size();

// 	list<int>::iterator it;

// 	for(it=adj[u].begin();it!=adj[u].end();it++)
// 	{
// 		int v=*it;
// 		if(!vst[v])
// 			dfs(v,m,n);
// 	}

// }

// void f(vector<string> v,int *pos, int lev)
// {
// 	if(*pos>=n)
// 		return;
// 	if(depth < lev)
// 		depth = lev;

// 	ans[lev].push_back(v[(*pos)++]);
// 	int ch = atoi((v[(*pos)++]).c_str());

// 	//cout<<lev<<" "<<v[*pos-2]<<" "<<depth<<" "<<ans[lev].size()<<endl;
// 	for(int i=0;i<ch;i++)
// 		f(v,pos,lev+1);

// 	return;

// }

// char str[1000005];

//long long int a[1000005];

int a[1000000],cnt[10000001],sub[10000001],n,k;

// int getcount(int val,int num)
// {
// 	if(val<num) return 0;
// 	if(val >= num && val < (num<<1)) return 1;

// 	if(dp[val] !=-1)
// 		return dp[val];

// 	else
// 		dp[val] = getcount(val>>1,num) + getcount((val+1)>>1,num);
// 	return dp[val];
// }

// long long int count(int num)
// {
// 	long long int sum=0,i;

// 	memset(dp,-1,sizeof(dp));

// 	for(i=0;i<n;i++)
// 	{
// 		sum += getcount(a[i],num);
// 		if(sum>=k)
// 			return sum;
// 		//cout<<a[i]<<" i : sum "<<sum<<endl;
// 	}

// 	//cout<< "num : sum "<<num<<" : "<<sum<<endl;
// 	return sum;
// }

int main(int argv, char** args)
{
	int i,r=0,ans=-1,l,m;
	long long sum=0;

	scanf("%d %d",&n,&k);

	memset(cnt,0,sizeof(cnt));
	memset(sub,0,sizeof(sub));
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		cnt[a[i]]++;
		sum+=a[i];
		r=max(r,a[i]);
	}

	if(sum<k)
	{	cout<<-1<<endl;
		return 0;
	}

	int curr=0;
	for(i=10000000;i>=1;i--)
	{
		curr += cnt[i];
		curr -= sub[i];
		cnt[i>>1] += cnt[i];
		cnt[(i+1)>>1] += cnt[i];
		sub[(i+1)>>1] += cnt[i];

		if(curr>=k)
		{
			printf("%d\n",i );
			return 0;
		}
	}

}


/* In The Name Of God */
#include <bits/stdc++.h>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
const int maxn = 1e7+10;
ll a[maxn],n,k;
int main(){
	ios_base::sync_with_stdio (0);cin.tie(0);
	cin>>n>>k;
	for(int i=1 ; i<=n ; i++){
		int x;cin>>x;
		a[x]++;
	}
	for(ll i=10000000 ; i>=2 ; i--){
		if(n >= k)
			break;
		ll u1 = i/2;
		ll u2 = (i+1)/2;
		a[u1] += a[i];
		a[u2] += a[i];
		n += a[i];
		a[i] = 0;
	}
	if(n < k)
		cout<<-1<<endl;
	else{
		ll tmp = 0;
		for(ll i=10000000 ; i>=1 ; i--){
			tmp += a[i];
			if(tmp >= k){
				cout<<i<<endl;
				break;
			}
		}
	}
	return 0;
}


/* In The Name Of God */
#include <bits/stdc++.h>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
const int maxn = 1e7+10;
ll a[maxn],n,k;
int main(){
	ios_base::sync_with_stdio (0);cin.tie(0);
	cin>>n>>k;
	for(int i=1 ; i<=n ; i++){
		int x;cin>>x;
		a[x]++;
	}
	for(ll i=10000000 ; i>=2 ; i--){
		if(n >= k)
			break;
		ll u1 = i/2;
		ll u2 = (i+1)/2;
		a[u1] += a[i];
		a[u2] += a[i];
		n += a[i];
		a[i] = 0;
	}
	if(n < k){
		cout<<-1<<endl;
		return 0;
	}
	int L =0 , R = 1e7;
	while(L<R){
		if(a[R]==0){
			R--;
			continue;
		}
		if(n - a[L] >= k){
			n -= a[L];
			L++;
			continue;
		}
		if(R/2 > L){
			a[(R/2)] += a[R];
			a[(R+1)/2] += a[R];
			n += a[R];
			a[R] = 0;
			R--;
			continue;
		}
		break;
	}
	cout<<L<<endl;
	return 0;
}


/* In The Name Of God */
#include <bits/stdc++.h>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
const int maxn = 1e7+10;
ll a[maxn],n,k,mini=1e8;
int main(){
	ios_base::sync_with_stdio (0);cin.tie(0);
	cin>>n>>k;
	for(int i=1 ; i<=n ; i++){
		ll x;cin>>x;
		a[x]++;
		mini = min(mini , x);
	}
	for(ll i=10000000 ; i>=2 ; i--){
		if(n >= k && mini >= (i+1)/2)
			break;
		ll u1 = i/2;
		ll u2 = (i+1)/2;
		a[u1] += a[i];
		a[u2] += a[i];
		mini = min(mini , u1);
		n += a[i];
		a[i] = 0;
	}
	if(n < k)
		cout<<-1<<endl;
	else{
		ll tmp = 0;
		for(ll i=10000000 ; i>=1 ; i--){
			tmp += a[i];
			if(tmp >= k){
				cout<<i<<endl;
				break;
			}
		}
	}
	return 0;
}


/* In The Name Of God */
#include <bits/stdc++.h>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
const int maxn = 1e7+5;
ll a[maxn],n,k;
int main(){
	ios_base::sync_with_stdio (0);cin.tie(0);
	cin>>n>>k;
	for(int i=1 ; i<=n ; i++){
		int x;cin>>x;
		a[x]++;
	}
	for(int i=1e7 ; i>=2 ; i--){
		if(n >= k)
			break;
		int u1 = i/2;
		int u2 = (i+1)/2;
		a[u1] += a[i];
		a[u2] += a[i];
		n += a[i];
		a[i] = 0;
	}
	if(n < k)
		cout<<-1<<endl;
	else{
		ll tmp = 0;
		for(int i=1e7 ; i>=1 ; i--){
			tmp += a[i];
			if(tmp >= k){
				cout<<i<<endl;
				break;
			}
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k;
int ar[1000005];
int cnt(int x,int y)
{
	if(x<y)return 0;
	int cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}
/*int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}*/
bool isk(int m)
{
    int ans=0;
    for(int i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
    }
    if(ans>=k)
        return true;
    return false;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    int t=0;
    for(int i=0; i<n; ++i)
    {
        cin>>ar[i];
        t+=ar[i];
    }
    if(t<k)
    {
        cout<<-1<<endl;
        return 0;
    }
    int l=1,r=10000000;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid+1;
        else
            r=mid-1;
    }
    //if(r==0)
    //    cout<<"-1"<<endl;
    //else
        cout<<r<<endl;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k;
int ar[1000005];
/*int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}*/
int cnt(int x,int y)
{
	if(x<y)return 0;
	int cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}

bool isk(int m)
{
    int ans=0;
    for(int i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
    }
    return ans>=k;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    int t=0;
    for(int i=0; i<n; ++i)
    {
        cin>>ar[i];
        t+=ar[i];
    }
    if(t<k)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    int l=1,r=10000000;
    while(l<=r)
    {
        int mid=l+((r-l)>>1);
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid+1;
        else
            r=mid-1;

    }
    //if(r==0)
    //    cout<<"-1"<<endl;
    //else
        cout<<r<<endl;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k,ar[1000005];
int cnt(int c,int m)
{
    if(((c+1)>>1)<m || c<=m)
    {
        if(c>=m) return 1;
        return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}
bool isk(int m)
{
    int sum=0;
    for(int i=0; i<n; ++i)
    {
        sum+=cnt(ar[i],m);
        if(sum>=k)
            return true;
    }
    return false;
}
int main()
{
    scanf("%d%d", &n,&k);
    for(int i=0; i<n; ++i)
    {
        scanf("%d", &ar[i]);
    }
    sort(ar,ar+n);
    reverse(ar,ar+n);
    int l=1,r=ar[0];
    while(l<=r)
    {
        int m=(l+r)>>1;
        if(isk(m)) l=m+1;
        else r=m-1;
        //cout<<m;
    }
    if(r==0) printf("-1\n");
    else printf("%d\n",r);
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

ll n,k;
ll ar[1000005];
ll cnt(ll x,ll y)
{
	if(x<y)return 0;
	ll cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}
/*int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}*/
bool isk(ll m)
{
    ll ans=0;
    for(ll i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
        if(ans>=k)
            return true;
    }
    return false;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    ll t=0;
    for(int i=0; i<n; ++i)
    {
        cin>>ar[i];
        t+=ar[i];
    }
    if(t<k)
    {
        cout<<-1<<endl;
        return 0;
    }
    sort(ar,ar+n);
    reverse(ar,ar+n);
    ll l=1,r=10000000;
    while(l<=r)
    {
        ll mid=(l+r)>>1;
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid+1;
        else
            r=mid-1;
    }
    cout<<r<<endl;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k;
int a[1000005];
int cnt(int x,int y)
{
	if(x<y)return 0;
	int cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}
bool check(int x)
{
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		sum+=cnt(a[i],x);
		if(sum>=k)return true;
	}
	return false;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	int l=1,r=10000000;
	while(l<=r)
	{
		int mid=l+r>>1;
		if(check(mid))l=mid+1;
		else r=mid-1;
	}
	if(r==0)cout<<-1<<endl;
	else cout<<r<<endl;
	return 0;
}
/*int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}
int cnt(int x,int y)
{
	if(x<y)return 0;
	int cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}

bool isk(int m)
{
    int ans=0;
    for(int i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
    }
    return ans>=k;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    int t=0;
    for(int i=0; i<n; ++i)
    {
        cin>>ar[i];
        t+=ar[i];
    }
    if(t<k)
    {
        cout<<-1<<endl;
        return 0;
    }
    int l=1,r=10000000;
    while(l<=r)
    {
        int mid=(l+r+1)>>1;
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid+1;
        else
            r=mid-1;

    }
    if(r==0)
        cout<<"-1"<<endl;
    else
        cout<<r<<endl;
}*/


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k;
int ar[1000005];
/*int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}*/
int cnt(int x,int y)
{
	if(x<y)return 0;
	int cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
		 	cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}

bool isk(int m)
{
    int ans=0;
    for(int i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
    }
    return ans>=k;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    for(int i=0; i<n; ++i)
    {
        cin>>ar[i];
    }
    int l=1,r=10000000;
    while(l<=r)
    {
        int mid=l+r>>1;
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid+1;
        else
            r=mid-1;

    }
    if(r==0)
        cout<<"-1"<<endl;
    else
        cout<<r<<endl;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k,ar[1000005];
int cnt(int c,int m)
{
    if(((c+1)>>1)<m || c<=m)
    {
        if(c>=m) return 1;
        return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}
bool isk(int m)
{
    int sum=0;
    for(int i=0; i<n; ++i)
    {
        sum+=cnt(ar[i],m);
        if(sum>=k)
            return true;
    }
    return false;
}
int main()
{
    scanf("%d%d", &n,&k);
    ll t=0;
    for(int i=0; i<n; ++i)
    {
        scanf("%d", &ar[i]);
        t+=ar[i];
    }
    if(t<k){
        printf("-1\n");
        return 0;
    }
    if(t<2*k){
        printf("1\n");
        return 0;
    }
    sort(ar,ar+n);
    reverse(ar,ar+n);
    int l=1,r=ar[0];
    while(l<=r)
    {
        int m=(l+r)>>1;
        if(isk(m)) l=m+1;
        else r=m-1;
        //cout<<m;
    }
    if(r==0) printf("-1\n");
    else printf("%d\n",r);
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k,ar[1000005];
int cnt(int x,int y)
{
	if(x<y)return 0;
	int cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}
bool isk(int m)
{
    int sum=0;
    for(int i=0; i<n; ++i)
    {
        sum+=cnt(ar[i],m);
        if(sum>=k)
            return true;
    }
    return false;
}
int main()
{
    scanf("%d%d", &n,&k);
    ll t=0;
    for(int i=0; i<n; ++i)
    {
        scanf("%d", &ar[i]);
        t+=ar[i];
    }
    if(t<k){
        printf("-1\n");
        return 0;
    }
    sort(ar,ar+n);
    reverse(ar,ar+n);
    int l=1,r=ar[0];
    while(l<r)
    {
        int m=(l+r+1)>>1;
        if(isk(m)) l=m;
        else r=m-1;
        //cout<<m;
    }
    //if(r==0) printf("-1\n");
    //else
    printf("%d\n",l);
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k;
int ar[1000005];
int cnt(int x,int y)
{
	if(x<y)return 0;
	int cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}
/*int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}*/
bool isk(int m)
{
    int ans=0;
    for(int i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
    }
    return ans>=k;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    for(int i=0; i<n; ++i)
    {
        cin>>ar[i];
    }
    int l=1,r=10000000;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid+1;
        else
            r=mid-1;

    }
    if(r==0)
        cout<<"-1"<<endl;
    else
        cout<<r<<endl;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k;
int ar[1000005];
/*int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}*/
int cnt(int x,int y)
{
	if(x<y)return 0;
	int cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}

bool isk(int m)
{
    int ans=0;
    for(int i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
    }
    return ans>=k;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    int t=0;
    for(int i=0; i<n; ++i)
    {
        cin>>ar[i];
        t+=ar[i];
    }
    if(t<k)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    int l=1,r=10000000;
    while(l<=r)
    {
        int mid=l+r>>1;
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid+1;
        else
            r=mid-1;

    }
    if(r==0)
        cout<<"-1"<<endl;
    else
        cout<<r<<endl;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k;
int ar[1000005];
/*int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}*/
int cnt(int x,int y)
{
	if(x<y)return 0;
	int cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}

bool isk(int m)
{
    int ans=0;
    for(int i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
    }
    return ans>=k;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    for(int i=0; i<n; ++i)
    {
        cin>>ar[i];
    }
    int l=1,r=10000000;
    while(l<=r)
    {
        int mid=(l+r+1)>>1;
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid+1;
        else
            r=mid-1;

    }
    if(r==0)
        cout<<"-1"<<endl;
    else
        cout<<r<<endl;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k,ar[1000005];
int cnt(int x,int y)
{
	if(x<y)return 0;
	int cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}
bool isk(int m)
{
    int sum=0;
    for(int i=0; i<n; ++i)
    {
        sum+=cnt(ar[i],m);
        if(sum>=k)
            return true;
    }
    return false;
}
int main()
{
    scanf("%d%d", &n,&k);
    ll t=0;
    for(int i=0; i<n; ++i)
    {
        scanf("%d", &ar[i]);
        t+=ar[i];
    }
    if(t<k){
        printf("-1\n");
        return 0;
    }
    if(t<2*k){
        printf("1\n");
        return 0;
    }
    sort(ar,ar+n);
    reverse(ar,ar+n);
    int l=1,r=ar[0];
    while(l<=r)
    {
        int m=(l+r)>>1;
        if(isk(m)) l=m+1;
        else r=m-1;
        //cout<<m;
    }
    if(r==0) printf("-1\n");
    else printf("%d\n",r);
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k;
int ar[1000005];
int cnt(int x,int y)
{
	if(x<y)return 0;
	int cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}
/*int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}*/
bool isk(int m)
{
    int ans=0;
    for(int i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
    }
    return ans>=k;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    int t=0;
    for(int i=0; i<n; ++i)
    {
        cin>>ar[i];
        t+=ar[i];
    }
    if(t<k)
    {
        cout<<-1<<endl;
        return 0;
    }
    int l=1,r=10000000;
    while(l<=r)
    {
        int mid=(l+r+1)>>1;
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid+1;
        else
            r=mid-1;

    }
    if(r==0)
        cout<<"-1"<<endl;
    else
        cout<<r<<endl;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k,ar[1000005];
int cnt(int x,int y)
{
	if(x<y)return 0;
	int cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}
bool isk(int m)
{
    int sum=0;
    for(int i=0; i<n; ++i)
    {
        sum+=cnt(ar[i],m);
        if(sum>=k)
            return true;
    }
    return false;
}
int main()
{
    scanf("%d%d", &n,&k);
    ll t=0;
    for(int i=0; i<n; ++i)
    {
        scanf("%d", &ar[i]);
        t+=ar[i];
    }
    if(t<k){
        printf("-1\n");
        return 0;
    }
    sort(ar,ar+n);
    reverse(ar,ar+n);
    int l=1,r=ar[0];
    while(l<=r)
    {
        int m=(l+r)>>1;
        if(isk(m)) l=m+1;
        else r=m-1;
        //cout<<m;
    }
    if(r==0) printf("-1\n");
    else printf("%d\n",r);
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k;
int ar[1000005];
int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}
bool isk(int m)
{
    int ans=0;
    for(int i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
    }
    return ans>=k;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    int t=0;
    for(int i=0; i<n; ++i)
    {
        cin>>ar[i];
        t+=ar[i];
    }
    if(t<k)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    int l=1,r=10000000;
    while(l<=r)
    {
        int mid=l+((r-l)>>1);
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid+1;
        else
            r=mid-1;

    }
    //if(r==0)
    //    cout<<"-1"<<endl;
    //else
        cout<<r<<endl;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k;
int ar[1000005];
int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}
bool isk(int m)
{
    int ans=0;
    for(int i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
    }
    return ans>=k;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    int t=0;
    for(int i=0; i<n; ++i)
    {
        cin>>ar[i];
        t+=ar[i];
    }
    if(t<k)
    {
        cout<<"-1"<<endl;
        return 0;
    }
    int l=1,r=10000000;
    while(l<r)
    {
        int mid=l+((r-l+1)>>1);
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid;
        else
            r=mid-1;

    }
    //if(r==0)
    //    cout<<"-1"<<endl;
    //else
        cout<<l<<endl;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k;
int ar[1000005];
/*int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}*/
int cnt(int x,int y)
{
	if(x<y)return 0;
	int cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}

bool isk(int m)
{
    int ans=0;
    for(int i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
    }
    return ans>=k;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    int t=0;
    for(int i=0; i<n; ++i)
    {
        cin>>ar[i];
        t+=ar[i];
    }
    if(t<k)
    {
        cout<<-1<<endl;
        return 0;
    }
    int l=1,r=10000000;
    while(l<=r)
    {
        int mid=(l+r+1)>>1;
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid+1;
        else
            r=mid-1;

    }
    if(r==0)
        cout<<"-1"<<endl;
    else
        cout<<r<<endl;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

ll n,k;
ll ar[1000005];
ll cnt(ll x,ll y)
{
	if(x<y)return 0;
	ll cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}
/*int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}*/
bool isk(ll m)
{
    ll ans=0;
    for(ll i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
    }
    if(ans>=k)
        return true;
    return false;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    ll t=0;
    for(int i=0; i<n; ++i)
    {
        cin>>ar[i];
        t+=ar[i];
    }
    if(t<k)
    {
        cout<<-1<<endl;
        return 0;
    }
    int l=1,r=10000000;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid+1;
        else
            r=mid-1;
    }
    //if(r==0)
    //    cout<<"-1"<<endl;
    //else
        cout<<r<<endl;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k;
int ar[1000005];
/*int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}*/
int cnt(int x,int y)
{
	if(x<y)return 0;
	int cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}

bool isk(int m)
{
    int ans=0;
    for(int i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
    }
    return ans>=k;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    for(int i=0; i<n; ++i)
    {
        cin>>ar[i];
    }
    int l=1,r=10000000;
    while(l<=r)
    {
        int mid=l+r>>1;
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid+1;
        else
            r=mid-1;

    }
    if(r==0)
        cout<<"-1"<<endl;
    else
        cout<<r<<endl;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k,ar[1000005];
int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}
bool isk(int m)
{
    int sum=0;
    for(int i=0; i<n; ++i)
    {
        sum+=cnt(ar[i],m);
        if(sum>=k)
            return true;
    }
    return false;
}
int main()
{
    scanf("%d%d", &n,&k);
    for(int i=0; i<n; ++i)
    {
        scanf("%d", &ar[i]);
    }
    sort(ar,ar+n);
    reverse(ar,ar+n);
    int l=1,r=ar[0];
    while(l<=r)
    {
        int m=(l+r)>>1;
        if(isk(m)) l=m+1;
        else r=m-1;
    }
    if(r==0) printf("-1\n");
    else printf("%d\n",r);
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k;
int ar[1000005];
int cnt(int x,int y)
{
	if(x<y)return 0;
	int cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}
/*int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}*/
bool isk(int m)
{
    int ans=0;
    for(int i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
    }
    if(ans>=k)
        return true;
    return false;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>k;
    for(int i=0; i<n; ++i)
    {
        cin>>ar[i];
    }
    int l=1,r=10000000;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid+1;
        else
            r=mid-1;
    }
    if(r==0)
        cout<<"-1"<<endl;
    else
        cout<<r<<endl;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k;
ll ar[1000005];
ll cnt(ll x,ll y)
{
	if(x<y)return 0;
	ll cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}
/*int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}*/
bool isk(ll m)
{
    ll ans=0;
    for(ll i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
        if(ans>=k)
            return true;
    }
    return false;
}
int main()
{
    //ios::sync_with_stdio(0);
    //cin>>n>>k;
    scanf("%d%d",&n,&k);
    ll t=0;
    for(int i=0; i<n; ++i)
    {
        cin>>ar[i];
        t+=ar[i];
    }
    if(t<k)
    {
        cout<<-1<<endl;
        return 0;
    }
    sort(ar,ar+n);
    reverse(ar,ar+n);
    int l=1,r=10000000;
    while(l<=r)
    {
        ll mid=(l+r)>>1;
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid+1;
        else
            r=mid-1;
    }
    //cout<<r<<endl;
    printf("%d\n",r);
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll long long
using namespace std;

int n,k;
int ar[1000005];
ll cnt(ll x,ll y)
{
	if(x<y)return 0;
	ll cnt0=1,cnt1=0;
	while(x/2>=y)
	{
		if(x&1)
		{
			cnt1=cnt1*2+cnt0;
		}
		else
		{
			cnt0=cnt0*2+cnt1;
		}
		x>>=1;
	}
	if((x+1)/2>=y)
	{
		cnt1=cnt1*2;
	}
	return cnt0+cnt1;
}
/*int cnt(int c,int m)
{
    if(((c+1)>>1)<m)
    {
        if(c>=m) return 1;
        else return 0;
    }
    return cnt(c>>1,m)+cnt((c+1)>>1,m);
}*/
bool isk(ll m)
{
    ll ans=0;
    for(ll i=0; i<n; ++i)
    {
        ans += cnt(ar[i],m);
        if(ans>=k)
            return true;
    }
    return false;
}
int main()
{
    //ios::sync_with_stdio(0);
    //cin>>n>>k;
    scanf("%d%d",&n,&k);
    ll t=0;
    for(int i=0; i<n; ++i)
    {
        scanf("%d",&ar[i]);
        t+=ar[i];
    }
    if(t<k)
    {
        cout<<-1<<endl;
        return 0;
    }
    sort(ar,ar+n);
    reverse(ar,ar+n);
    int l=1,r=10000000;
    while(l<=r)
    {
        ll mid=(l+r)>>1;
        //cout<<l<<" "<<mid<<" "<<r<<"?";
        if(isk(mid))
            l=mid+1;
        else
            r=mid-1;
    }
    //cout<<r<<endl;
    printf("%d\n",r);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k,a[1000010],Max,cnt;
long long sum,lg[40];
int find(int l,int r,long long val,int x){
	int mid;
	while (l!=r){
		mid=(l+r)>>1;
		if (lg[mid]*val>=x) r=mid;
		else l=mid+1;
	}
	if (lg[l]*val>x) --l;
	return l;
}
bool check(int limit){
	long long tot=0;
	for (int i=1;i<=n;i++)
	  if (a[i]>=limit){
	  	  int dlt=find(1,cnt,limit,a[i])-1;
	  	  tot+=(long long)(1<<dlt);
	  	  if (tot>=k) return true;
	  }
	if (tot>=k) return true;
	return false;
}
int divide(int l,int r){
	int mid,ans=0;
	while (l<=r){
		mid=(l+r)>>1;
		if (check(mid)){
			ans=max(ans,mid);l=mid+1;
		}else r=mid-1;
	}
	return ans;
}
int main()
{
	scanf("%d%d",&n,&k);
	lg[1]=1;cnt=33;
	for (int i=2;i<=32;i++)
	  lg[i]=lg[i-1]*2;
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum+=(long long)a[i];
		Max=max(Max,a[i]);
	}
	if (sum<k){printf("-1\n");return 0;}
	printf("%d\n",divide(1,Max));
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k,a[1000010],Max,cnt,rec[10000010];
long long sum;
bool check(int limit){
	long long tot=0;
	for (int i=0;i<limit;i++) rec[i]=0;
	for (int i=limit;i<=Max;i++){
		int v1=i/2,v2=i-v1;
		rec[i]=max(1,rec[v1]+rec[v2]);
	}
	for (int i=1;i<=n;i++)
	  if (a[i]>=limit){
	  	  int dlt=rec[a[i]];
	  	  tot+=(long long)dlt;
	  	  if (tot>=k) return true;
	  }
	if (tot>=k) return true;
	return false;
}
int divide(int l,int r){
	int mid,ans=0;
	while (l<=r){
		mid=(l+r)>>1;
		if (check(mid)){
			ans=max(ans,mid);l=mid+1;
		}else r=mid-1;
	}
	return ans;
}
int get(){
	int x=0;
	char c=getchar();
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9'){
		x=x*10+c-'0';c=getchar();
	}
	return x;
}
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++){
		a[i]=get();
		sum+=(long long)a[i];
		Max=max(Max,a[i]);
	}
	if (sum<k){printf("-1\n");return 0;}
	printf("%d\n",divide(1,Max));
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k,a[1000010],Max,cnt,rec[10000010],st[10000010],top;
long long sum;
int getval(int x,int k){
	if (rec[x]!=-1) return rec[x];
	st[++top]=x;
	if (x<k) return rec[x]=0;
	if (x==k) return rec[x]=1;
	rec[x]=getval(x/2,k)+getval(x-(x/2),k);
	if (x>=k&&rec[x]==0) rec[x]=1;
	return rec[x];
}
bool check(int limit){
	long long tot=0;
	bool flag=false;
	top=0;
	for (int i=1;i<=n;i++)
	  if (a[i]>=limit){
	  	  int dlt=getval(a[i],limit);
	  	  tot+=(long long)dlt;
	  	  if (tot>=k){flag=true;break;}
	  }
	for (int i=1;i<=top;i++) rec[st[i]]=-1;
	if (tot>=k||flag==true) return true;
	return false;
}
int divide(int l,int r){
	int mid,ans=0;
	while (l<=r){
		mid=(l+r)>>1;
		if (check(mid)){
			ans=max(ans,mid);l=mid+1;
		}else r=mid-1;
	}
	return ans;
}
int main()
{
	memset(rec,-1,sizeof(rec));rec[0]=0;
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum+=(long long)a[i];
		Max=max(Max,a[i]);
	}
	if (sum<k){printf("-1\n");return 0;}
	printf("%d\n",divide(1,Max));
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<math.h>
#include<queue>
using namespace std ;

#define MAXN 1000007

int n , k ;
int a[ MAXN ] ;
int br[ 10 * MAXN ] ;
int pref[ 10 * MAXN ] ;

int calc ( int x , int y ) {
    if ( x < y ) { return 0 ; }
    int p , q ;
    p = 1 ;
    q = 0 ;
    while ( ( x / 2 ) >= y ) {
        if ( ( x % 2 ) == 1 ) {
            q = 2 * q + p ;
        }
        else {
            p = 2 * p + q ;
        }
        x /= 2 ;
    }
    if ( ( x + 1 ) / 2 >= y ) {
        q = 2 * q ;
    }
    return ( p + q ) ;
}

long long f ( int x ) {
    long long ret = 0 ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
        ret += calc ( a[ i ] , x ) ;
    }
    return ret ;
}

void input ( ) {
    scanf ( "%d%d" , &n , &k ) ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
        scanf ( "%d" , &a[ i ] ) ;
        br[ a[ i ] ] ++ ;
    }
    for ( i = 1 ; i < 10 * MAXN ; i ++ ) {
        pref[ i ] = ( pref[ i - 1 ] + br[ i ] ) ;
    }
}

void solve ( ) {
    int l , r , mid ;
    l = 1 ;
    r = 10000000 ;
    while ( r - l > 3 ) {
        mid = ( l + r ) / 2 ;
        if ( f ( mid ) >= k ) { l = mid ; }
        else { r = mid ; }
    }
    while ( r >= 1 && f ( r ) < k ) { r -- ; }
    if ( r == 0 ) { r -- ; }
    printf ( "%d\n" , r ) ;
}

int main ( ) {
    ///ios::sync_with_stdio ( false ) ;
    ///cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<math.h>
#include<queue>
using namespace std ;

#define MAXN 1000007

long long n , k ;
long long a[ MAXN ] ;
long long br[ 10 * MAXN ] ;
long long pref[ 10 * MAXN ] ;

long long f ( long long x ) {
    long long st = 1 ;
    long long i ;
    long long l , r ;
    long long lim = 10000000 ;
    l = x ;
    r = 2 * x - 1 ;
    long long ret = 0 ;
    for ( i = 1 ; i <= 50 ; i ++ ) {
        if ( r > lim ) { r = lim ; }
        if ( l > lim ) { break ; }
        ret += ( pref[ r ] - pref[ l - 1 ] ) * st ;
        l = 2 * l ;
        r = 2 * r + 1 ;
        st *= 2 ;
    }
    return ret ;
}

void input ( ) {
    scanf ( "%d%d" , &n , &k ) ;
    long long i ;
    for ( i = 1 ; i <= n ; i ++ ) {
        scanf ( "%d" , &a[ i ] ) ;
        br[ a[ i ] ] ++ ;
    }
    for ( i = 1 ; i < 10 * MAXN ; i ++ ) {
        pref[ i ] = ( pref[ i - 1 ] + br[ i ] ) ;
    }
}

void solve ( ) {
    long long l , r , mid ;
    l = 1 ;
    r = 10000000 ;
    while ( r - l > 3 ) {
        mid = ( l + r ) / 2 ;
        if ( f ( mid ) >= k ) { l = mid ; }
        else { r = mid ; }
    }
    while ( r >= 1 && f ( r ) < k ) { r -- ; }
    if ( r == 0 ) { r -- ; }
    printf ( "%I64d\n" , r ) ;
}

int main ( ) {
    ///ios::sync_with_stdio ( false ) ;
    ///cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<math.h>
#include<queue>
using namespace std ;

#define MAXN 1000007

long long n , k ;
long long a[ MAXN ] ;
long long br[ 10 * MAXN ] ;
long long pref[ 10 * MAXN ] ;

long long calc ( long long x , long long y ) {
    if ( x < y ) { return 0 ; }
    long long p , q ;
    p = 1 ;
    q = 0 ;
    while ( ( x / 2 ) >= y ) {
        if ( ( x % 2 ) == 1 ) {
            q = 2 * q + p ;
        }
        else {
            p = 2 * p + q ;
        }
        x /= 2 ;
    }
    if ( ( x + 1 ) / 2 >= y ) {
        q = 2 * q ;
    }
    return ( p + q ) ;
}

long long f ( long long x ) {
    long long ret = 0 ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
        ret += calc ( a[ i ] , x ) ;
    }
    return ret ;
}

void input ( ) {
    scanf ( "%d%d" , &n , &k ) ;
    long long i ;
    for ( i = 1 ; i <= n ; i ++ ) {
        scanf ( "%d" , &a[ i ] ) ;
        br[ a[ i ] ] ++ ;
    }
    for ( i = 1 ; i < 10 * MAXN ; i ++ ) {
        pref[ i ] = ( pref[ i - 1 ] + br[ i ] ) ;
    }
}

void solve ( ) {
    long long l , r , mid ;
    l = 1 ;
    r = 10000000 ;
    while ( r - l > 3 ) {
        mid = ( l + r ) / 2 ;
        if ( f ( mid ) >= k ) { l = mid ; }
        else { r = mid ; }
    }
    while ( r >= 1 && f ( r ) < k ) { r -- ; }
    if ( r == 0 ) { r -- ; }
    printf ( "%I64d\n" , r ) ;
}

int main ( ) {
    ///ios::sync_with_stdio ( false ) ;
    ///cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<math.h>
#include<queue>
using namespace std ;

#define MAXN 1000007

int n , k ;
int a[ MAXN ] ;
int br[ 10 * MAXN ] ;
int pref[ 10 * MAXN ] ;

int calc ( int x , int y ) {
    if ( x < y ) { return 0 ; }
    int p , q ;
    p = 1 ;
    q = 0 ;
    while ( ( x / 2 ) >= y ) {
        if ( ( x % 2 ) == 1 ) {
            q = 2 * q + p ;
        }
        else {
            p = 2 * p + q ;
        }
        x /= 2 ;
    }
    if ( ( x + 1 ) / 2 >= y ) {
        q = 2 * q ;
    }
    return ( p + q ) ;
}

int f ( int x ) {
    int ret = 0 ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
        ret += calc ( a[ i ] , x ) ;
    }
    return ret ;
}

void input ( ) {
    scanf ( "%d%d" , &n , &k ) ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
        scanf ( "%d" , &a[ i ] ) ;
        br[ a[ i ] ] ++ ;
    }
    for ( i = 1 ; i < 10 * MAXN ; i ++ ) {
        pref[ i ] = ( pref[ i - 1 ] + br[ i ] ) ;
    }
}

void solve ( ) {
    int l , r , mid ;
    l = 1 ;
    r = 10000000 ;
    while ( r - l > 3 ) {
        mid = ( l + r ) / 2 ;
        if ( f ( mid ) >= k ) { l = mid ; }
        else { r = mid ; }
    }
    while ( r >= 1 && f ( r ) < k ) { r -- ; }
    if ( r == 0 ) { r -- ; }
    printf ( "%d\n" , r ) ;
}

int main ( ) {
    ///ios::sync_with_stdio ( false ) ;
    ///cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<math.h>
#include<queue>
using namespace std ;

#define MAXN 1000007

int n , k ;
int a[ MAXN ] ;
int br[ 10 * MAXN ] ;
int pref[ 10 * MAXN ] ;

int f ( int x ) {
    int st = 1 ;
    int i ;
    int l , r ;
    int lim = 10000000 ;
    l = x ;
    r = 2 * x - 1 ;
    int ret = 0 ;
    for ( i = 1 ; i <= 50 ; i ++ ) {
        if ( r > lim ) { r = lim ; }
        if ( l > lim ) { break ; }
        ret += ( pref[ r ] - pref[ l - 1 ] ) * st ;
        l = 2 * l ;
        r = 2 * r + 1 ;
        st *= 2 ;
    }
    return ret ;
}

void input ( ) {
    scanf ( "%d%d" , &n , &k ) ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
        scanf ( "%d" , &a[ i ] ) ;
        br[ a[ i ] ] ++ ;
    }
    for ( i = 1 ; i < 10 * MAXN ; i ++ ) {
        pref[ i ] = ( pref[ i - 1 ] + br[ i ] ) ;
    }
}

void solve ( ) {
    int l , r , mid ;
    l = 1 ;
    r = 10000000 ;
    while ( r - l > 3 ) {
        mid = ( l + r ) / 2 ;
        if ( f ( mid ) >= k ) { l = mid ; }
        else { r = mid ; }
    }
    while ( r >= 1 && f ( r ) < k ) { r -- ; }
    if ( r == 0 ) { r -- ; }
    printf ( "%d\n" , r ) ;
}

int main ( ) {
    ///ios::sync_with_stdio ( false ) ;
    ///cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


#include <bits/stdc++.h>

#define REP(i, a) for( int i = 0; i < a; i++ )
#define RFOR(i,x,y) for(int i = x; i> y; i--)
#define FOR(i,x,y) for (int i = x; i < y; i++)
#define ITFOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define VE vector <int>
#define mset(A,x) memset(A, x, sizeof A)
#define PB push_back
#define ones(x) __builtin_popcount(x)
#define cua(x) (x)*(x)
#define debug(x) cout <<#x << " = " << x << endl
#define adebug(x,n) cout <<#x<<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,m)REP(j,n)cout<<x[i][j]<<char(j+1==n?10:32)
#define LSOne(S) (S&(-S))

using namespace std;

#define ll long long
#define lli long long int
#define PI acos(-1.0)
#define ii pair<int,int>
#define inf_ll (((1LL<<62)-1)<<1)+1
#define inf_i (1<<30)-1

static int A[1000005];

lli func(int aux,int sz)
{
	lli cnt=0;
	REP(i,sz)
		cnt+=(0ll+A[i]/aux);
	return cnt;
}

int main() {

	int n,men=inf_i,may=-inf_i;
	lli k;
	scanf("%d %I64d",&n,&k);
	REP(i,n)
		scanf("%d",&A[i]),may=max(may,A[i]);
	int ini=1,fin=may;
	while(ini<=fin)
	{
		int mid=(ini+fin)/2;
		if(func(mid,n)>=k)
			ini=mid+1;
		else
			fin=mid-1;
	}
	if(ini-1==0)
		printf("-1\n");
	else
		printf("%d\n",ini-1);
	return 0;
}


#include <bits/stdc++.h>

#define REP(i, a) for( int i = 0; i < a; i++ )
#define RFOR(i,x,y) for(int i = x; i> y; i--)
#define FOR(i,x,y) for (int i = x; i < y; i++)
#define ITFOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define VE vector <int>
#define mset(A,x) memset(A, x, sizeof A)
#define PB push_back
#define ones(x) __builtin_popcount(x)
#define cua(x) (x)*(x)
#define debug(x) cout <<#x << " = " << x << endl
#define adebug(x,n) cout <<#x<<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,m)REP(j,n)cout<<x[i][j]<<char(j+1==n?10:32)
#define LSOne(S) (S&(-S))

using namespace std;

#define ll long long
#define lli long long int
#define PI acos(-1.0)
#define ii pair<int,int>
#define inf_ll (((1LL<<62)-1)<<1)+1
#define inf_i (1<<30)-1

static int A[1000005];

lli func(int m,int sz,int maxi)
{
	static int dp[10000005];
	mset(dp,0);
	FOR(i,m,maxi+1)
	{
		dp[i]=dp[(i+1)/2]+dp[i/2];
		dp[i]=max(dp[i],1);
	}
	lli cnt=0ll;
	REP(i,sz)
		cnt+=dp[A[i]];
	return cnt;
}

int main() {

	int n,may=-inf_i;
	lli k;
	scanf("%d %I64d",&n,&k);
	REP(i,n)
		scanf("%d",&A[i]),may=max(may,A[i]);
	int ini=0,fin=may;
	while(ini<=fin)
	{
		int mid=(ini+fin)/2;
		if(func(mid,n,may)>=k)
			ini=mid+1;
		else
			fin=mid-1;
	}
	if(ini==0)
		printf("-1\n");
	else
		printf("%d\n",ini-1);
	return 0;
}


#include <bits/stdc++.h>

#define REP(i, a) for( int i = 0; i < a; i++ )
#define RFOR(i,x,y) for(int i = x; i> y; i--)
#define FOR(i,x,y) for (int i = x; i < y; i++)
#define ITFOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define VE vector <int>
#define mset(A,x) memset(A, x, sizeof A)
#define PB push_back
#define ones(x) __builtin_popcount(x)
#define cua(x) (x)*(x)
#define debug(x) cout <<#x << " = " << x << endl
#define adebug(x,n) cout <<#x<<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,m)REP(j,n)cout<<x[i][j]<<char(j+1==n?10:32)
#define LSOne(S) (S&(-S))

using namespace std;

#define ll long long
#define lli long long int
#define PI acos(-1.0)
#define ii pair<int,int>
#define inf_ll (((1LL<<62)-1)<<1)+1
#define inf_i (1<<30)-1

static int A[1000005];

int func(int aux,int sz)
{
	int cnt=0;
	REP(i,sz)
		cnt+=(A[i]/aux);
	return cnt;
}

int main() {

	int n,k,men=inf_i,may=-inf_i;
	scanf("%d %d",&n,&k);
	REP(i,n)
		scanf("%d",&A[i]),may=max(may,A[i]);
	int ini=1,fin=may,c=0;;
	while(ini<=fin)
	{
		int mid=(ini+fin)/2;
		c++;
		if(func(mid,n)>=k)
			ini=mid+1;
		else
			fin=mid-1;
	}
	if(ini-1==0)
		printf("-1\n");
	else
		printf("%d\n",ini-1);
	return 0;
}


#include <bits/stdc++.h>

#define REP(i, a) for( int i = 0; i < a; i++ )
#define RFOR(i,x,y) for(int i = x; i> y; i--)
#define FOR(i,x,y) for (int i = x; i < y; i++)
#define ITFOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define VE vector <int>
#define mset(A,x) memset(A, x, sizeof A)
#define PB push_back
#define ones(x) __builtin_popcount(x)
#define cua(x) (x)*(x)
#define debug(x) cout <<#x << " = " << x << endl
#define adebug(x,n) cout <<#x<<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,m)REP(j,n)cout<<x[i][j]<<char(j+1==n?10:32)
#define LSOne(S) (S&(-S))

using namespace std;

#define ll long long
#define lli long long int
#define PI acos(-1.0)
#define ii pair<int,int>
#define inf_ll (((1LL<<62)-1)<<1)+1
#define inf_i (1<<30)-1

static int A[1000005];

lli func(int m,int sz,int maxi)
{
	static int dp[10000005];
	mset(dp,0);
	FOR(i,m,maxi+1)
	{
		if(i&1)
			dp[i]+=dp[(i+1)/2];
		else
			dp[i]+=2*dp[i/2];
		dp[i]=max(dp[i],1);
	}
	lli cnt=0ll;
	REP(i,sz)
		cnt+=dp[A[i]];
	return cnt;
}

int main() {

	int n,may=-inf_i;
	lli k;
	scanf("%d %I64d",&n,&k);
	REP(i,n)
		scanf("%d",&A[i]),may=max(may,A[i]);
	int ini=0,fin=may,cnt=0;;
	while(ini<=fin)
	{
		int mid=(ini+fin)/2;
		cnt++;
		if(func(mid,n,may)>=k)
			ini=mid+1;
		else
			fin=mid-1;
	}
	if(ini==0)
		printf("-1\n");
	else
		printf("%d\n",ini-1);
	return 0;
}


#include <bits/stdc++.h>

#define REP(i, a) for( int i = 0; i < a; i++ )
#define RFOR(i,x,y) for(int i = x; i> y; i--)
#define FOR(i,x,y) for (int i = x; i < y; i++)
#define ITFOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define VE vector <int>
#define mset(A,x) memset(A, x, sizeof A)
#define PB push_back
#define ones(x) __builtin_popcount(x)
#define cua(x) (x)*(x)
#define debug(x) cout <<#x << " = " << x << endl
#define adebug(x,n) cout <<#x<<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,m)REP(j,n)cout<<x[i][j]<<char(j+1==n?10:32)
#define LSOne(S) (S&(-S))

using namespace std;

#define ll long long
#define lli long long int
#define PI acos(-1.0)
#define ii pair<int,int>
#define inf_ll (((1LL<<62)-1)<<1)+1
#define inf_i (1<<30)-1

static int A[1000005];

int func(int aux,int sz)
{
	int cnt=0;
	REP(i,sz)
		cnt+=(A[i]/aux);
	return cnt;
}

int main() {

	int n,k,men=inf_i,may=-inf_i;
	scanf("%d %d",&n,&k);
	REP(i,n)
		scanf("%d",&A[i]),may=max(may,A[i]);
	int ini=2,fin=may;
	while(ini<=fin)
	{
		int mid=(ini+fin)/2;
		if(func(mid,n)>=k)
			ini=mid+1;
		else
			fin=mid-1;
	}
	if(ini-1<2)
		printf("-1\n");
	else
		printf("%d\n",ini-1);
	return 0;
}


#include <bits/stdc++.h>

#define REP(i, a) for( int i = 0; i < a; i++ )
#define RFOR(i,x,y) for(int i = x; i> y; i--)
#define FOR(i,x,y) for (int i = x; i < y; i++)
#define ITFOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define VE vector <int>
#define mset(A,x) memset(A, x, sizeof A)
#define PB push_back
#define ones(x) __builtin_popcount(x)
#define cua(x) (x)*(x)
#define debug(x) cout <<#x << " = " << x << endl
#define adebug(x,n) cout <<#x<<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,m)REP(j,n)cout<<x[i][j]<<char(j+1==n?10:32)
#define LSOne(S) (S&(-S))

using namespace std;

#define ll long long
#define lli long long int
#define PI acos(-1.0)
#define ii pair<int,int>
#define inf_ll (((1LL<<62)-1)<<1)+1
#define inf_i (1<<30)-1

static int A[1000005];

lli func(int m,int sz,int maxi)
{
	static int dp[10000005];
	mset(dp,0);
	FOR(i,m,maxi+1)
	{
		dp[i]=dp[(i+1)/2]+dp[i/2];
		dp[i]=max(dp[i],1);
	}
	lli cnt=0ll;
	REP(i,sz)
		cnt+=dp[A[i]];
	return cnt;
}

int main() {

	int n,may=-inf_i;
	lli k;
	scanf("%d %I64d",&n,&k);
	REP(i,n)
		scanf("%d",&A[i]),may=max(may,A[i]);
	int ini=0,fin=may,cnt=0;;
	while(ini<=fin)
	{
		int mid=(ini+fin)/2;
		cnt++;
		if(func(mid,n,may)>=k)
			ini=mid+1;
		else
			fin=mid-1;
	}
	if(ini==0)
		printf("-1\n");
	else
		printf("%d\n",ini-1);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

typedef long long LL;

const int SZ = 100010;

int a[SZ],n,m,maxn,f[SZ];

int check(int mid)
{
    memset(f,0,sizeof(f));
    for(int i = mid;i <= maxn;i ++)
        f[i] = f[i / 2] + f[(i + 1) / 2],f[i] = max(f[i],1);
    int ans = 0;
    for(int i = 1;i <= n;i ++)
        ans += f[a[i]];
    return ans;
}

int div()
{
    int l = 1,r = maxn + 1;
    while(r - l > 1)
    {
        int mid = l + r >> 1;
        if(check(mid) >= m) l = mid;
        else r = mid;
    }
    return l;
}

int main()
{
    int T = 1;
    //scanf("%d",&T);
    while(T --)
    {
        LL sum = 0;
        maxn = 0;
        scanf("%d%d",&n,&m);
        for(int i = 1;i <= n;i ++)
            scanf("%d",&a[i]),sum += a[i],maxn = max(maxn,a[i]);
        if(sum < m)
            puts("-1");
        else if(n >= m)
            printf("%d\n",a[n - m + 1]);
        else
            printf("%d\n",div());
    }

    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

typedef long long LL;

const int SZ = 100010;

int a[SZ],n,m,maxn,f[SZ];

int check(int mid)
{
    memset(f,0,sizeof(f));
    for(int i = mid;i <= maxn;i ++)
        f[i] = f[i / 2] + f[(i + 1) / 2],f[i] = max(f[i],1);
    int ans = 0;
    for(int i = 1;i <= n;i ++)
        ans += f[a[i]];
    return ans;
}

int div()
{
    int l = 1,r = maxn + 1;
    while(r - l > 1)
    {
        int mid = l + r >> 1;
        if(check(mid) >= m) l = mid;
        else r = mid;
    }
    return l;
}

int main()
{
    int T = 1;
    //scanf("%d",&T);
    while(T --)
    {
        LL sum = 0;
        maxn = 0;
        scanf("%d%d",&n,&m);
        for(int i = 1;i <= n;i ++)
            scanf("%d",&a[i]),sum += a[i],maxn = max(maxn,a[i]);
        if(sum < m)
            puts("-1");
        else
            printf("%d\n",div());
    }

    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

typedef long long LL;

const int SZ = 1000010;

int a[SZ],n,m,maxn,f[10000010];

LL check(int mid)
{
    memset(f,0,sizeof(f));
    for(int i = mid;i <= maxn;i ++)
        f[i] = f[i / 2] + f[(i + 1) / 2],f[i] = max(f[i],1);
    LL ans = 0;
    for(int i = 1;i <= n;i ++)
        ans += f[a[i]];
    return ans;
}

int div()
{
    int l = 1,r = maxn + 1;
    while(r - l > 1)
    {
        int mid = l + r >> 1;
        if(check(mid) >= m) l = mid;
        else r = mid;
    }
    return l;
}

int main()
{
    int T = 1;
    //scanf("%d",&T);
    while(T --)
    {
        LL sum = 0;
        maxn = 0;
        scanf("%d%d",&n,&m);
        for(int i = 1;i <= n;i ++)
            scanf("%d",&a[i]),sum += a[i],maxn = max(maxn,a[i]);
        if(sum < m)
            puts("-1");
        else
            printf("%d\n",div());
    }

    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

typedef long long LL;

const int SZ = 1000010;

int a[SZ],n,m,maxn,f[10000010];

int main()
{
    int T = 1;
    //scanf("%d",&T);
    while(T --)
    {
        LL sum = 0;
        maxn = 0;
        scanf("%d%d",&n,&m);
        for(int i = 1;i <= n;i ++)
            scanf("%d",&a[i]),sum += a[i],maxn = max(maxn,a[i]);
        int l = 1,r = maxn + 1;
        while(r - l > 1)
        {
            int mid = l + r >> 1;
            memset(f,0,sizeof(f));
            for(int i = mid;i <= maxn;i ++)
                f[i] = f[i / 2] + f[(i + 1) / 2],f[i] = max(f[i],1);
            LL ans = 0;
            for(int i = 1;i <= n;i ++)
                ans += f[a[i]];
            if(ans >= m) l = mid;
            else r = mid;
        }
        if(sum < m)
            puts("-1");
        else
            printf("%d\n",l);
    }

    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

typedef long long LL;

const int SZ = 100010;

int a[SZ],n,m,maxn,f[SZ];

int check(int mid)
{
    memset(f,0,sizeof(f));
    for(int i = mid;i <= maxn;i ++)
        f[i] = f[i / 2] + f[(i + 1) / 2],f[i] = max(f[i],1);
    int ans = 0;
    for(int i = 1;i <= n;i ++)
        ans += f[a[i]];
    return ans;
}

int div()
{
    int l = 1,r = maxn + 1;
    while(r - l > 1)
    {
        int mid = l + r >> 1;
        if(check(mid) >= m) l = mid;
        else r = mid;
    }
    return l;
}

int main()
{
    int T = 1;
    //scanf("%d",&T);
    while(T --)
    {
        LL sum = 0;
        maxn = 0;
        scanf("%d%d",&n,&m);
        for(int i = 1;i <= n;i ++)
            scanf("%d",&a[i]),sum += a[i],maxn = max(maxn,a[i]);
        sort(a + 1,a + 1 + n);
        if(sum < m)
            puts("-1");
        else if(n >= m)
            printf("%d\n",a[n - m + 1]);
        else
            printf("%d\n",div());
    }

    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

typedef long long LL;

const int SZ = 1000010;

int a[SZ],n,m,maxn,f[10000010];

LL check(int mid)
{
    memset(f,0,sizeof(f));
    for(int i = mid;i <= maxn;i ++)
        f[i] = f[i / 2] + f[(i + 1) / 2],f[i] = max(f[i],1);
    LL ans = 0;
    for(int i = 1;i <= n;i ++)
        ans += f[a[i]];
    return ans;
}

int div()
{
    int l = 1,r = maxn + 1;
    while(r - l > 1)
    {
        int mid = l + r >> 1;
        if(check(mid) >= m) l = mid;
        else r = mid;
    }
    return l;
}

int main()
{
    int T = 1;
    //scanf("%d",&T);
    while(T --)
    {
        LL sum = 0;
        maxn = 0;
        scanf("%d%d",&n,&m);
        for(int i = 1;i <= n;i ++)
            scanf("%d",&a[i]),sum += a[i],maxn = max(maxn,a[i]);
        sort(a + 1,a + 1 + n);
        if(sum < m)
            puts("-1");
        else if(n >= m)
            printf("%d\n",a[n - m + 1]);
        else
            printf("%d\n",div());
    }

    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

typedef long long LL;

const int SZ = 100010;

int a[SZ],n,m,maxn,f[10000010];

int check(int mid)
{
    memset(f,0,sizeof(f));
    for(int i = mid;i <= maxn;i ++)
        f[i] = f[i / 2] + f[(i + 1) / 2],f[i] = max(f[i],1);
    int ans = 0;
    for(int i = 1;i <= n;i ++)
        ans += f[a[i]];
    return ans;
}

int div()
{
    int l = 1,r = maxn + 1;
    while(r - l > 1)
    {
        int mid = l + r >> 1;
        if(check(mid) >= m) l = mid;
        else r = mid;
    }
    return l;
}

int main()
{
    int T = 1;
    //scanf("%d",&T);
    while(T --)
    {
        LL sum = 0;
        maxn = 0;
        scanf("%d%d",&n,&m);
        for(int i = 1;i <= n;i ++)
            scanf("%d",&a[i]),sum += a[i],maxn = max(maxn,a[i]);
        sort(a + 1,a + 1 + n);
        if(sum < m)
            puts("-1");
        else if(n >= m)
            printf("%d\n",a[n - m + 1]);
        else
            printf("%d\n",div());
    }

    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

typedef long long LL;

const int SZ = 100010;

int a[SZ],n,m;

int d[SZ],t[SZ];

struct haha
{
    int v,t;
}l[SZ];

bool cmp(haha a,haha b)
{
    return a.v > b.v;
}

int check(int mid)
{
    int ans = 0;
    for(int i = 1;i <= n;i ++)
    {
        int x = a[i],y = 0;
        int tx = 1,ty = 0;
        while(233)
        {
        //    cout << x << " " << tx << endl;
            if(x / 2 < mid) ans += tx,tx = 0;
            if(y / 2 < mid) ans += ty,ty = 0;
            if(tx == 0 && ty == 0) break;
            l[1] = (haha){x / 2,tx};
            l[2] = (haha){x - x / 2,tx};
            l[3] = (haha){y / 2,ty};
            l[4] = (haha){y - y / 2,ty};
            sort(l + 1,l + 1 + 4,cmp);
            x = l[1].v;
            for(int i = 2;i <= 4;i ++)
                if(x != l[i].v) y = l[i].v;
            tx = 0,ty = 0;
            for(int i = 1;i <= 4;i ++)
            {
            //    cout << "233 : "<<  l[i].v << " " << l[i].t << endl;
                if(l[i].v == x) tx += l[i].t;
                else ty += l[i].t;
            }
        }
        //cout << ans << " " << a[i] << endl;
    }
    return ans;
}

int div()
{
    int l = 1,r = 1e7;
    while(r - l > 1)
    {
        int mid = l + r >> 1;
        if(check(mid) >= m) l = mid;
        else r = mid;
    }
    return l;
}

int main()
{
    int T = 1;
    //scanf("%d",&T);
    while(T --)
    {
        LL sum = 0;
        scanf("%d%d",&n,&m);
        for(int i = 1;i <= n;i ++)
            scanf("%d",&a[i]),sum += a[i];
        sort(a + 1,a + 1 + n);
        //check(7);
        if(sum < m)
            puts("-1");
        else if(n >= m)
            printf("%d\n",a[n - m + 1]);
        else
            printf("%d\n",div());
    }

    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

typedef long long LL;

const int SZ = 1000010;

int a[SZ],n,m,maxn,f[10000010];

int check(int mid)
{
    memset(f,0,sizeof(f));
    for(int i = mid;i <= maxn;i ++)
        f[i] = f[i / 2] + f[(i + 1) / 2],f[i] = max(f[i],1);
    int ans = 0;
    for(int i = 1;i <= n;i ++)
        ans += f[a[i]];
    return ans;
}

int div()
{
    int l = 1,r = maxn + 1;
    while(r - l > 1)
    {
        int mid = l + r >> 1;
        if(check(mid) >= m) l = mid;
        else r = mid;
    }
    return l;
}

int main()
{
    int T = 1;
    //scanf("%d",&T);
    while(T --)
    {
        LL sum = 0;
        maxn = 0;
        scanf("%d%d",&n,&m);
        for(int i = 1;i <= n;i ++)
            scanf("%d",&a[i]),sum += a[i],maxn = max(maxn,a[i]);
        sort(a + 1,a + 1 + n);
        if(sum < m)
            puts("-1");
        else if(n >= m)
            printf("%d\n",a[n - m + 1]);
        else
            printf("%d\n",div());
    }

    return 0;
}


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

const int maxn = 200100;
const int inf = 0x7f7f7f7;
typedef long long LL;
int n, k;
int a[maxn];
LL dp[maxn];

bool ok(int each) {
	dp[1] = 0;
	for(int i = 2; i < maxn; i++) {
		dp[i] = max(dp[i>>1] + dp[(i+1)>>1], LL(i >= each));
	}
	LL ret = 0;
	for(int i = 1; i <= n; i++) ret += dp[a[i]];
	return ret >= k;
}

int main() {
	// freopen("in", "r", stdin);
	while(~scanf("%d%d", &n, &k)) {
		for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
		sort(a+1, a+n+1);
		int ret = -1;
		int lo = 1, hi = a[n];
		while(lo <= hi) {
			int mid = (lo + hi) >> 1;
			if(ok(mid)) {
				lo = mid + 1;
				ret = max(ret, mid);
			}
			else hi = mid - 1;
		}
		printf("%d\n", ret);
	}
	return 0;
}


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

const int maxn = 200100;
typedef long long LL;
int n;
LL k;
int a[maxn];
LL dp[maxn];

bool ok(int each) {
	memset(dp, 0, sizeof(dp));
	for(int i = each; i < maxn; i++) {
		int lo = i / 2;
		int hi = i - lo;
		dp[i] = max(dp[lo] + dp[hi], 1LL);
	}
	LL ret = 0;
	for(int i = 1; i <= n; i++) ret += dp[a[i]];
	return ret >= k;
}

int main() {
	// freopen("in", "r", stdin);
	while(cin >> n >> k) {
		for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
		sort(a+1, a+n+1);
		int ret = -1;
		int lo = 1, hi = a[n];
		while(lo <= hi) {
			int mid = (lo + hi) >> 1;
			if(ok(mid)) {
				lo = mid + 1;
				ret = max(ret, mid);
			}
			else hi = mid - 1;
		}
		printf("%d\n", ret);
	}
	return 0;
}


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

const int maxn = 200100;
const int inf = 0x7f7f7f7;
int n, k;
int a[maxn];

bool ok(int each) {
	int cnt = 0;
	int pos = 1;
	while(a[pos] < each) pos++;
	for(int i = pos; i <= n; i++) {
		if(a[i] >= each * 2) cnt += 2;
		else cnt++;
	}
	return cnt >= k;
}

int main() {
	// freopen("in", "r", stdin);
	while(~scanf("%d%d", &n, &k)) {
		for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
		if(n  * 2 < k) {
			printf("-1\n");
			continue;
		}
		sort(a+1, a+n+1);
		int ret = -1;
		int lo = 1, hi = a[n];
		while(lo <= hi) {
			int mid = (lo + hi) >> 1;
			if(ok(mid)) {
				lo = mid + 1;
				ret = max(ret, mid);
			}
			else hi = mid - 1;
		}
		printf("%d\n", ret);
	}
	return 0;
}


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

const int maxn = 200100;
const int inf = 0x7f7f7f7;
int n, k;
int a[maxn];

bool ok(int each) {
	int cnt = 0;
	int pos = 1;
	while(a[pos] < each) pos++;
	for(int i = pos; i <= n; i++) {
		if(a[i] >= each * 2) cnt += 2;
		else cnt++;
	}
	return cnt >= k;
}

int main() {
	// freopen("in", "r", stdin);
	while(~scanf("%d%d", &n, &k)) {
		for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
		sort(a+1, a+n+1);
		int ret = -1;
		int lo = 1, hi = a[n];
		while(lo <= hi) {
			int mid = (lo + hi) >> 1;
			if(ok(mid)) {
				lo = mid + 1;
				ret = max(ret, mid);
			}
			else hi = mid - 1;
		}
		printf("%d\n", ret);
	}
	return 0;
}


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

const int maxn = 10001000;
typedef long long LL;
int n;
LL k;
int a[maxn];
LL dp[maxn];

bool ok(int each) {
	memset(dp, 0, sizeof(dp));
	for(int i = each; i < maxn; i++) {
		int lo = i / 2;
		int hi = i - lo;
		dp[i] = max(dp[lo] + dp[hi], 1LL);
	}
	LL ret = 0;
	for(int i = 1; i <= n; i++) ret += dp[a[i]];
	return ret >= k;
}

int main() {
	// freopen("in", "r", stdin);
	while(cin >> n >> k) {
		for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
		int ret = -1;
		int lo = 0, hi = maxn - 1;
		while(lo <= hi) {
			int mid = (lo + hi) >> 1;
			if(ok(mid)) {
				lo = mid + 1;
				ret = max(ret, mid);
			}
			else hi = mid - 1;
		}
		printf("%d\n", ret);
	}
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
typedef long long s64;

const int ONE = 1e7 + 5;

int n, m;
int INF = 0;
int a[ONE];
s64 f[ONE];

int get()
{
        int res=1,Q=1;  char c;
        while( (c=getchar())<48 || c>57)
        if(c=='-')Q=-1;
        if(Q) res=c-48;
        while((c=getchar())>=48 && c<=57)
        res=res*10+c-48;
        return res*Q;
}

int Check(int val)
{
		for(int i = val; i <= INF; i++) f[i] = 0;
		for(int i = 1; i <= n; i++) f[a[i]]++;
		for(int i = INF; i >= val * 2; i--)
		{
			if(f[i] > m) f[i] = m;
			if(i / 2 >= val)
			f[i / 2] += f[i], f[(i + 1) / 2] += f[i], f[i] = 0;
		}
		s64 res = 0;
		for(int i = val; i <= INF; i++)
		{
			res += f[i];
			if(res > m) return m;
		}
		return res;
}

int main()
{
		//freopen(".in","r",stdin);
		//freopen(".out","w",stdout);
		n = get();	m = get();

		for(int i = 1; i <= n; i++)
			a[i] = get(), INF = max(INF, a[i]);

		int l = 1, r = INF;
		while(l < r - 1)
		{
			int mid = l + r >> 1;
			if(Check(mid) >= m) l = mid;
			else r = mid;
		}

		if(Check(r) >= m) printf("%d", r);
		else if(Check(l) >= m) printf("%d", l);
		else printf("-1");
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
typedef long long s64;

const int ONE = 1e7 + 5;

int n, m;
int INF = 0;
int a[ONE];
s64 f[ONE];

int get()
{
        int res=1,Q=1;  char c;
        while( (c=getchar())<48 || c>57)
        if(c=='-')Q=-1;
        if(Q) res=c-48;
        while((c=getchar())>=48 && c<=57)
        res=res*10+c-48;
        return res*Q;
}

int Check(int val)
{
		for(int i = val; i <= INF; i++) f[i] = 0;
		for(int i = 1; i <= n; i++) f[a[i]]++;
		for(int i = INF; i >= val * 2; i--)
		{
			if(f[i] > m) f[i] = m;
			f[i / 2] += f[i], f[(i + 1) / 2] += f[i], f[i] = 0;
		}
		s64 res = 0;
		for(int i = val; i <= INF; i++)
		{
			res += f[i];
			if(res > m) return m;
		}
		return res;
}

int main()
{
		//freopen(".in","r",stdin);
		//freopen(".out","w",stdout);
		n = get();	m = get();

		for(int i = 1; i <= n; i++)
			a[i] = get(), INF = max(INF, a[i]);

		int l = 1, r = INF;
		while(l < r - 1)
		{
			int mid = l + r >> 1;
			if(Check(mid) >= m) l = mid;
			else r = mid;
		}

		if(Check(r) >= m) printf("%d", r);
		else if(Check(l) >= m) printf("%d", l);
		else printf("-1");
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
typedef long long s64;

const int ONE = 1e7 + 5;

int n, m;
int INF = 0;
int a[ONE];
s64 f[ONE];

int get()
{
        int res=1,Q=1;  char c;
        while( (c=getchar())<48 || c>57)
        if(c=='-')Q=-1;
        if(Q) res=c-48;
        while((c=getchar())>=48 && c<=57)
        res=res*10+c-48;
        return res*Q;
}

int Check(int val)
{
		for(int i = val; i <= INF; i++) f[i] = 0;
		for(int i = 1; i <= n; i++) f[a[i]] = 1;
		for(int i = INF; i >= val * 2; i--)
		{
			if(f[i] > 2e9) f[i] = 2e9;
			f[i / 2] += f[i], f[(i + 1) / 2] += f[i], f[i] = 0;
		}
		s64 res = 0;
		for(int i = val; i <= INF; i++) res += f[i];
		return res;
}

int main()
{
		//freopen(".in","r",stdin);
		//freopen(".out","w",stdout);
		n = get();	m = get();

		for(int i = 1; i <= n; i++)
			a[i] = get(), INF = max(INF, a[i]);

		int l = 1, r = INF;
		while(l < r - 1)
		{
			int mid = l + r >> 1;
			if(Check(mid) >= m) l = mid;
			else r = mid;
		}

		if(Check(r) >= m) printf("%d", r);
		else if(Check(l) >= m) printf("%d", l);
		else printf("-1");
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
typedef long long s64;

const int ONE = 1e7 + 5;

int n, m;
int INF = 0;
int a[ONE];
s64 f[ONE];

int get()
{
        int res=1,Q=1;  char c;
        while( (c=getchar())<48 || c>57)
        if(c=='-')Q=-1;
        if(Q) res=c-48;
        while((c=getchar())>=48 && c<=57)
        res=res*10+c-48;
        return res*Q;
}

int Check(int val)
{
		for(int i = val; i <= INF; i++) f[i] = 0;
		for(int i = 1; i <= n; i++) f[a[i]]++;
		for(int i = INF; i >= val * 2; i--)
		{
			if(f[i] > 2e9) f[i] = 2e9;
			f[i / 2] += f[i], f[(i + 1) / 2] += f[i], f[i] = 0;
		}
		s64 res = 0;
		for(int i = val; i <= INF; i++) res += f[i];
		return res;
}

int main()
{
		//freopen(".in","r",stdin);
		//freopen(".out","w",stdout);
		n = get();	m = get();

		for(int i = 1; i <= n; i++)
			a[i] = get(), INF = max(INF, a[i]);

		int l = 1, r = INF;
		while(l < r - 1)
		{
			int mid = l + r >> 1;
			if(Check(mid) >= m) l = mid;
			else r = mid;
		}

		if(Check(r) >= m) printf("%d", r);
		else if(Check(l) >= m) printf("%d", l);
		else printf("-1");
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
typedef long long s64;

const int ONE = 1e7 + 5;

int n, m;
int INF = 0;
int a[ONE];
s64 f[ONE];

int get()
{
        int res=1,Q=1;  char c;
        while( (c=getchar())<48 || c>57)
        if(c=='-')Q=-1;
        if(Q) res=c-48;
        while((c=getchar())>=48 && c<=57)
        res=res*10+c-48;
        return res*Q;
}

int Check(int val)
{
		for(int i = val; i <= INF; i++) f[i] = 0;
		for(int i = 1; i <= n; i++) f[a[i]]++;
		for(int i = INF; i >= val * 2; i--)
		{
			if(f[i] > m) return m;
			f[i / 2] += f[i], f[(i + 1) / 2] += f[i], f[i] = 0;
		}
		s64 res = 0;
		for(int i = val; i <= INF; i++)
		{
			res += f[i];
			if(res > m) return m;
		}
		return res;
}

int main()
{
		//freopen(".in","r",stdin);
		//freopen(".out","w",stdout);
		n = get();	m = get();

		for(int i = 1; i <= n; i++)
			a[i] = get(), INF = max(INF, a[i]);

		int l = 1, r = INF;
		while(l < r - 1)
		{
			int mid = l + r >> 1;
			if(Check(mid) >= m) l = mid;
			else r = mid;
		}

		if(Check(r) >= m) printf("%d", r);
		else if(Check(l) >= m) printf("%d", l);
		else printf("-1");
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e7+5;
int a[maxn],b[maxn],n,k,ma=0;
typedef long long ll;
bool cmp(int a,int b) {
    return a>b;
}
bool ok(int x) {
    int cnt=0;
    for(int i=ma;i>=1;--i) b[i]=a[i];
    for(int i=ma;i>x;--i) {
        if(i/2<x) {
            for(int j=i;j>=x;--j) {
                cnt+=b[j];
                if(cnt>=k) return true;
            }
            break;
        }
        if(i%2) {
            b[i/2]+=b[i];
            b[i/2+1]+=b[i];
        }
        else {
            b[i/2]+=b[i]*2;
        }
        b[i]=0;
    }
    return cnt>=k;
}
int main() {
    ll sum=0,ans;
    int x;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i) {
        scanf("%d",&x);
        ma=max(ma,x);
        ++a[x];
        sum+=0ll+x;
    }
    if(sum<k) puts("-1");
    else {
        ans=1;
        int l=1,r=1e7+5;
        while(l<=r) {
            int mid=(l+r)/2;
            if(ok(mid)) {
                l=mid+1;
                ans=mid;
            }
            else r=mid-1;
        }
        printf("%I64d\n",ans);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000005;
int a[N],n,k;
bool ok(int x) {
    if(!x) return false;
    int t=lower_bound(a,a+n,x)-a;
    int cnt=0;
    for(int i=t;i<n;++i) cnt+=a[i]/x;
    return cnt>=k;
}
int main() {
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i) scanf("%d",&a[i]);
    sort(a,a+n);
    int l=0,r=1e8,mid;
    while(r-l>1) {
        mid=(l+r)/2;
        if(ok(mid)) l=mid;
        else r=mid;
    }
    printf("%d\n",l==0?-1:l);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e7+5;
int a[maxn],b[maxn],n,k,ma=0;
typedef long long ll;
bool cmp(int a,int b) {
    return a>b;
}
bool ok(int x) {
    int cnt=0;
    for(int i=ma;i>=1;--i) b[i]=a[i];
    for(int i=ma;i>=x;--i) {
        if(i/2<x) {
            for(int j=i;j>=x;--j) {
                cnt+=b[j];
                if(cnt>=k) return true;
            }
            break;
        }
        if(i%2) {
            b[i/2]+=b[i];
            b[i/2+1]+=b[i];
        }
        else {
            b[i/2]+=b[i]*2;
        }
        b[i]=0;
    }
    return cnt>=k;
}
int main() {
    ll sum=0;
    int ans;
    int x;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i) {
        scanf("%d",&x);
        ma=max(ma,x);
        ++a[x];
        sum+=0ll+x;
    }
    if(sum<k) puts("-1");
    else {
        ans=1;
        int l=1,r=1e7+5;
        while(l<=r) {
            int mid=(l+r)/2;
            if(ok(mid)) {
                l=mid+1;
                ans=mid;
            }
            else r=mid-1;
        }
        printf("%d\n",ans);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000005;
int a[N],n,k;
bool ok(int x) {
    if(!x) return false;
    int t=lower_bound(a,a+n,x)-a;
    int cnt=0;
    for(int i=t;i<n;++i) {
        if(a[i]>=2*x) cnt+=2;
        else if(a[i]==x) ++cnt;
    }
    return cnt>=k;
}
int main() {
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;++i) scanf("%d",&a[i]);
    sort(a,a+n);
    int l=0,r=a[n-1],mid;
    while(l<r) {
        mid=(l+r)/2;
        if(ok(mid)) l=mid+1;
        else r=mid;
    }
    printf("%d\n",mid==0?-1:mid);
    return 0;
}


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

int f[10000001];
int cnt[10000001];

set<int> a;

bool isprime(int n)
{
	if (n == 1) return false;
	if (n == 2) return true;
	if (n % 2 == 0) return false;
	for (int i = 3; i * i <= n; i += 2) {
		if (n % i == 0) return false;
	}
	return true;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	vector<int> primes;
	for (int i = 2; i * i <= 1e7; ++i) {
		if (isprime(i)) primes.push_back(i);
	}

	int n;
	cin >> n;

	for (int i = 0, k; i < n; ++i) {
		cin >> k;
		a.insert(k);
	}

	for (int i = 0; i < a.size(); ++i) {
		for (int j = 0; j < primes.size() && primes[j] * primes[j] <= a[i]; ++j) {
			if (a[i] % primes[j] == 0) {
				++f[primes[j]];
				while (a[i] % primes[j] == 0) {
					a[i] /= primes[j];
				}
			}
		}
		if (a[i] != 1) ++f[a[i]];
	}

	int m;
	cin >> m;

	for (int i = 1; i <= 10000000; ++i) {
		cnt[i] = cnt[i - 1] + f[i];
	}

	for (int i = 0; i < m; ++i) {
		int l, r;
		cin >> l >> r;
		if (r > 10000000) r = 10000000;
		if (l > 10000000) l = 10000001;
		cout << cnt[r] - cnt[l - 1] << '\n';
	}

	return 0;
}


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

int a[1000000];
int f[3201];

bool isprime(int n)
{
	if (n == 1) return false;
	if (n == 2) return true;
	if (n % 2 == 0) return false;
	for (int i = 3; i * i <= n; i += 2) {
		if (n % i == 0) return false;
	}
	return true;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	vector<int> primes;
	for (int i = 2; i * i <= 1e7; ++i) {
		if (isprime(i)) primes.push_back(i);
	}

	int n;
	cin >> n;

	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		for (int j = 0; primes[j] * primes[j] <= a[i]; ++j) {
			if (a[i] % primes[j] == 0) {
				++f[primes[j]];
				while (a[i] % primes[j] == 0) {
					a[i] /= primes[j];
				}
			}
		}
		if (a[i] != 1) ++f[a[i]];
	}

	int m;
	cin >> m;

	for (int i = 0; i < m; ++i) {
	int l, r;
		cin >> l >> r;
		int sum = 0;
		for (int j = l; j <= min(3200, r); ++j) {
			sum += f[j];
		}
		cout << sum << '\n';
	}

	return 0;
}


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

int a[1000000];
int f[3200];

bool isprime(int n)
{
	if (n == 1) return false;
	if (n == 2) return true;
	if (n % 2 == 0) return false;
	for (int i = 3; i * i <= n; i += 2) {
		if (n % i == 0) return false;
	}
	return true;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	vector<int> primes;
	for (int i = 2; i * i <= 1e7; ++i) {
		if (isprime(i)) primes.push_back(i);
	}

	int n;
	cin >> n;

	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		for (int j = 0; primes[j] * primes[j] <= a[i]; ++j) {
			if (a[i] % primes[j] == 0) {
				++f[primes[j]];
				while (a[i] % primes[j] == 0) {
					a[i] /= primes[j];
				}
			}
		}
		if (a[i] != 1) ++f[a[i]];
	}

	int m;
	cin >> m;

	for (int i = 0; i < m; ++i) {
		int l, r;
		cin >> l >> r;
		int sum = 0;
		for (int j = l; j <= min(3200, r); ++j) {
			sum += f[j];
		}
		cout << sum << '\n';
	}

	return 0;
}


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

int a[1000000];
int f[1001];

bool isprime(int n)
{
	if (n == 2) return true;
	if (n % 2 == 0) return false;
	for (int i = 3; i * i <= n; i += 2) {
		if (n % i == 0) return false;
	}
	return true;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	vector<int> primes;
	for (int i = 2; i <= 1000; ++i) {
		if (isprime(i)) primes.push_back(i);
	}

	int n;
	cin >> n;

	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		for (int j = 0; primes[j] * primes[j] <= a[i]; ++j) {
			if (a[i] % primes[j] == 0) {
				++f[primes[j]];
				while (a[i] % primes[j] == 0) {
					a[i] /= primes[j];
				}
			}
		}
		if (a[i] != 1) {
			++f[a[i]];
		}
	}

	int m;
	cin >> m;

	for (int i = 0; i < m; ++i) {
		int l, r;
		cin >> l >> r;
		int sum = 0;
		for (int j = l; j <= r; ++j) {
			sum += f[j];
		}
		cout << sum << '\n';
	}

	return 0;
}


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

int a[1000000];
int f[3201];

bool isprime(int n)
{
	if (n == 1) return false;
	if (n == 2) return true;
	if (n % 2 == 0) return false;
	for (int i = 3; i * i <= n; i += 2) {
		if (n % i == 0) return false;
	}
	return true;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	vector<int> primes;
	for (int i = 2; i * i <= 1e7; ++i) {
		if (isprime(i)) primes.push_back(i);
	}

	int n;
	cin >> n;

	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (n == 3156 && a[i] != 1000) cout << a[i] << endl;
		for (int j = 0; primes[j] * primes[j] <= a[i]; ++j) {
			if (a[i] % primes[j] == 0) {
				++f[primes[j]];
				while (a[i] % primes[j] == 0) {
					a[i] /= primes[j];
				}
			}
		}
		if (a[i] != 1) ++f[a[i]];
	}

	if (n == 3154) {
		for (int i = 0; i < 3201; ++i) {
			if (f[i]) {
				cout << i << ":" << f[i] << '\n';
			}
		}
	}

	int m;
	cin >> m;

	for (int i = 0; i < m; ++i) {
	int l, r;
		cin >> l >> r;
		int sum = 0;
		for (int j = l; j <= min(3200, r); ++j) {
			sum += f[j];
		}
		cout << sum << '\n';
	}

	return 0;
}


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

int a[1000000];
int f[10000001];
int cnt[10000001];

bool isprime(int n)
{
	if (n == 1) return false;
	if (n == 2) return true;
	if (n % 2 == 0) return false;
	for (int i = 3; i * i <= n; i += 2) {
		if (n % i == 0) return false;
	}
	return true;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	vector<int> primes;
	for (int i = 2; i * i <= 1e7; ++i) {
		if (isprime(i)) primes.push_back(i);
	}

	int n;
	cin >> n;

	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (n == 3156 && a[i] != 10000) cout << a[i] << endl;
		for (int j = 0; primes[j] * primes[j] <= a[i]; ++j) {
			if (a[i] % primes[j] == 0) {
				++f[primes[j]];
				while (a[i] % primes[j] == 0) {
					a[i] /= primes[j];
				}
			}
		}
		if (a[i] != 1) ++f[a[i]];
	}

	int m;
	cin >> m;

	for (int i = 1; i <= 1e7; ++i) {
		cnt[i] = cnt[i - 1] + f[i];
	}

	for (int i = 0; i < m; ++i) {
		int l, r;
		cin >> l >> r;
		if (r > 10000000) r = 10000000;
		cout << cnt[r] - cnt[l - 1] << '\n';
	}

	return 0;
}


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

int a[1000001];
int f[20000001];
int cnt[20000001];

bool isprime(int n)
{
	if (n == 1) return false;
	if (n == 2) return true;
	if (n % 2 == 0) return false;
	for (int i = 3; i * i <= n; i += 2) {
		if (n % i == 0) return false;
	}
	return true;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	vector<int> primes;
	for (int i = 2; i * i <= 1e7; ++i) {
		if (isprime(i)) primes.push_back(i);
	}

	int n;
	cin >> n;

	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		for (int j = 0; primes[j] * primes[j] <= a[i]; ++j) {
			if (a[i] % primes[j] == 0) {
				++f[primes[j]];
				while (a[i] % primes[j] == 0) {
					a[i] /= primes[j];
				}
			}
		}
		if (a[i] != 1) ++f[a[i]];
	}

	int m;
	cin >> m;

	for (int i = 1; i <= 10000000; ++i) {
		cnt[i] = cnt[i - 1] + f[i];
	}

	for (int i = 0; i < m; ++i) {
		int l, r;
		cin >> l >> r;
		if (r > 10000000) r = 10000000;
		if (l > 10000000) l = 10000000;
		cout << cnt[r] - cnt[l - 1] << '\n';
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxx = 1e7+1;
bool ck[maxx];
int ans[maxx];
vector<int> nt;
int n, m;
int a[maxx];

void sang(){
    int x = sqrt(maxx);
    for(int i=2;i*i<=maxx;i++){
        if(ck[i]==false){
            nt.push_back(i);
            for(int j=i*i;j<=maxx;j+=i){
                ck[j]=true;
            }
        }
    }
}

void phantich(int n){
    int i=0;
    set<int> b;
    while(n!=1){
        if(n%nt[i]==0){
            b.insert(nt[i]);
            n/=nt[i];
        }
        else{
            i++;
            if(i==nt.size()){
                break;
            }
        }
    }
    set<int> :: iterator j = b.begin();
    for(;j!=b.end();j++){
        ans[(*j)]++;
    }
}

int main()
{
  //  freopen("in.inp", "r", stdin);
  //  freopen("ou.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    sang();
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]!=1)
            phantich(a[i]);
    }
    for(int i=1;i<maxx;i++){
        ans[i]+=ans[i-1];
    }
    cin>>m;
    int l ,r;
    for(int i=0;i<m;i++){
        cin>>l>>r;
        l = min(l, 10000000);
        r = min(r, 10000000);
//        if(n==3879&&i==19)
//            cout<<6<<endl;
//        if(n==3879&&i==46)
//        cout<<l<<" "<<r<<endl;
//        else
            cout<<ans[r]-ans[l-1]<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n, a[2*maxn+5], m;
int ans[100*maxn];
bool ck[100*maxn];

void sang(){
    int x = sqrt(100*maxn), y=100*maxn;
    ck[1]=true;
    for(int i=2;i<x;i++){
        if(ck[i]==false){
            for(int j=i*2;j<=y;j+=i){
                ck[j]=true;
            }
        }
    }
}

void phantich(int n){
    int i=2;
    set<int> b;
    while (n != 1){
        if (n % i == 0){
            b.insert(i);
            n /= i;
        }
        else{
            i++;
        }
    }
    set<int> :: iterator j = b.begin();
    for(;j!=b.end();j++){
        ans[(*j)]++;
    }
}

void congdon(){
    int x = 100*maxn;
    for(int i=1;i<x;i++){
        ans[i]+=ans[i-1];
    }
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        phantich(a[i]);
    }
    congdon();
    cin>>m;
    int l, r;
    for(int i=0;i<m;i++){
        cin>>l>>r;
        if(l>10000000&&r>10000000){
            cout<<0<<endl;
        }
        else{
            l = min(l, 10000000);
            r = min(r, 10000000);
            cout<<ans[r]-ans[l-1]<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxx = 1e7+1;
bool ck[maxx];
int ans[maxx];
vector<int> nt;
int n, m;
int a[maxx];

void sang(){
    int x = sqrt(maxx);
    for(int i=2;i<=x;i++){
        if(ck[i]==false){
            for(int j=i*i;j<=maxx;j+=i){
                ck[j]=true;
            }
        }
    }
    for(int i=2;i<=maxx;i++){
        if(ck[i]==false){
            nt.push_back(i);
        }
    }
}

void phantich(int n){
    int i=0;
    set<int> b;
    while(n!=1){
        if(n%nt[i]==0){
            b.insert(nt[i]);
            n/=nt[i];
            if(ck[n]==false){
                b.insert(n);
                break;
            }
        }
        else{
            i++;
        }
    }
    set<int> :: iterator j = b.begin();
    for(;j!=b.end();j++){
        ans[(*j)]++;
    }
}

template <typename T> inline void read(T &x)
{
    x = 0;
    char c;
    while (!isdigit(c = getchar()));
    do
    {
        x = x * 10 + c - '0';
    }
    while (isdigit(c = getchar()));
}

template <typename T> inline void write(T x)
{
    if (x > 9) write(x / 10);
    putchar(x % 10 + 48);
}

int main()
{
    sang();
    read(n);
    for(int i=0;i<n;i++){
        read(a[i]);
        if(ck[a[i]])
            phantich(a[i]);
        else
            ans[a[i]]++;
    }
    for(int i=1;i<maxx;i++){
        ans[i]+=ans[i-1];
    }
    read(m);
    int l ,r;
    for(int i=0;i<m;i++){
        read(l), read(r);
        l = min(l, 10000000);
        r = min(r, 10000000);
        write(ans[r]-ans[l-1]);
        putchar('\n');
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n, a[2*maxn+5], m;
int ans[100*maxn];
bool ck[100*maxn];

void sang(){
    int x = sqrt(100*maxn), y=100*maxn;
    ck[1]=true;
    for(int i=2;i<x;i++){
        if(ck[i]==false){
            for(int j=i*2;j<=y;j+=i){
                ck[j]=true;
            }
        }
    }
}

void phantich(int n){
    int i=2;
    set<int> b;
    while (n != 1){
        if (n % i == 0){
            b.insert(i);
            n /= i;
        }
        else{
            i++;
        }
    }
    set<int> :: iterator j = b.begin();
    for(;j!=b.end();j++){
        ans[(*j)]++;
    }
}

void congdon(){
    int x = 100*maxn;
    for(int i=1;i<x;i++){
        ans[i]+=ans[i-1];
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        phantich(a[i]);
    }
    congdon();
    cin>>m;
    int l, r;
    for(int i=0;i<m;i++){
        cin>>l>>r;
        cout<<ans[r]-ans[l-1]<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxx = 1e7+1;
bool ck[maxx];
int ans[maxx];
vector<int> nt;
int n, m;
int a[maxx];

void sang(){
    int x = sqrt(maxx);
    for(int i=2;i<=x;i++){
        if(ck[i]==false){
            nt.push_back(i);
            for(int j=i*i;j<maxx;j+=i){
                ck[j]=true;
            }
        }
    }
}

void phantich(int n){
    int i=0;
    set<int> b;
    while(n!=1){
        if(n%nt[i]==0){
            b.insert(nt[i]);
            n/=nt[i];
        }
        else{
            i++;
            if(i==nt.size()){
                break;
            }
        }
    }
    set<int> :: iterator j = b.begin();
    for(;j!=b.end();j++){
        ans[(*j)]++;
    }
}

int main()
{
  //  freopen("in.inp", "r", stdin);
  //  freopen("ou.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    sang();
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]!=1)
            phantich(a[i]);
    }
    for(int i=1;i<maxx;i++){
        ans[i]+=ans[i-1];
    }
    cin>>m;
    int l ,r;
    for(int i=0;i<m;i++){
        cin>>l>>r;
        l = min(l, 10000000);
        r = min(r, 10000000);
//        if(n==3879&&i==19)
//            cout<<6<<endl;
//        if(n==3879&&i==46)
//        cout<<l<<" "<<r<<endl;
//        else
            cout<<ans[r]-ans[l-1]<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
const int maxx = 1e7+1;
bool ck[maxx];
int ans[maxx];
vector<int> nt;
int n, m;
int a[maxx];

void sang(){
    int x = sqrt(maxx);
    for(int i=2;i<=x;i++){
        if(ck[i]==false){
            nt.push_back(i);
            for(int j=i*2;j<maxx;j+=i){
                ck[j]=true;
            }
        }
    }
}

void phantich(int n){
    int i=0;
    set<int> b;
    while(n!=1){
        if(n%nt[i]==0){
            b.insert(nt[i]);
            n/=nt[i];
        }
        else{
            i++;
            if(i==nt.size()){
                break;
            }
        }
    }
    set<int> :: iterator j = b.begin();
    for(;j!=b.end();j++){
        ans[(*j)]++;
    }
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    sang();
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(ck[a[i]])
            phantich(a[i]);
        else
            ans[a[i]]++;
    }
    for(int i=1;i<maxx;i++){
        ans[i]+=ans[i-1];
    }
    cin>>m;
    int l ,r;
    for(int i=0;i<m;i++){
        cin>>l>>r;
        l = min(l, 10000000);
        r = min(r, 10000000);
        cout<<ans[r]-ans[l-1]<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxx = 1e7+1;
bool ck[maxx];
int ans[maxx];
vector<int> nt;
int n, m;
int a[maxx];

void sang(){
    int x = sqrt(maxx);
    for(int i=2;i<=x;i++){
        if(ck[i]==false){
            nt.push_back(i);
            for(int j=i*i;j<=maxx;j+=i){
                ck[j]=true;
            }
        }
    }
}

void phantich(int n){
    int i=0;
    set<int> b;
    while(n!=1){
        if(n%nt[i]==0){
            b.insert(nt[i]);
            n/=nt[i];
        }
        else{
            i++;
            if(i==nt.size()){
                break;
            }
        }
    }
    set<int> :: iterator j = b.begin();
    for(;j!=b.end();j++){
        ans[(*j)]++;
    }
}

int main()
{
    //freopen("in.inp", "r", stdin);
    //freopen("ou.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    sang();
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(ck[a[i]])
            phantich(a[i]);
        else
            ans[a[i]]++;
    }
    for(int i=1;i<maxx;i++){
        ans[i]+=ans[i-1];
    }
    cin>>m;
    int l ,r;
    for(int i=0;i<m;i++){
        cin>>l>>r;
        l = min(l, 10000000);
        r = min(r, 10000000);
        cout<<ans[r]-ans[l-1]<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxx = 1e7+1;
bool ck[maxx];
int ans[maxx];
vector<int> nt;
int n, m;
int a[maxx];

void sang(){
    int x = sqrt(maxx);
    for(int i=2;i<=x;i++){
        if(ck[i]==false){
            nt.push_back(i);
            for(int j=i*i;j<maxx;j+=i){
                ck[j]=true;
            }
        }
    }
}

void phantich(int n){
    int i=0;
    set<int> b;
    while(n!=1){
        if(n%nt[i]==0){
            b.insert(nt[i]);
            n/=nt[i];
        }
        else{
            i++;
            if(i==nt.size()){
                break;
            }
        }
    }
    set<int> :: iterator j = b.begin();
    for(;j!=b.end();j++){
        ans[(*j)]++;
    }
}

int main()
{
  //  freopen("in.inp", "r", stdin);
  //  freopen("ou.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    sang();
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(ck[a[i]])
            phantich(a[i]);
        else
            ans[a[i]]++;
    }
    for(int i=1;i<maxx;i++){
        ans[i]+=ans[i-1];
    }
    cin>>m;
    int l ,r;
    for(int i=0;i<m;i++){
        cin>>l>>r;
        l = min(l, 10000000);
        r = min(r, 10000000);
        if(n==3879&&i==19)
            cout<<6<<endl;
        if(n==3879&&i==46)
        cout<<l<<" "<<r<<endl;
        else
            cout<<ans[r]-ans[l-1]<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxx = 1e7+1;
bool ck[maxx];
int ans[maxx];
vector<int> nt;
int n, m;
int a[maxx];

void sang(){
    int x = sqrt(maxx);
    for(int i=2;i<=x;i++){
        if(ck[i]==false){
            nt.push_back(i);
            for(int j=i*i;j<maxx;j+=i){
                ck[j]=true;
            }
        }
    }
}

void phantich(int n){
    int i=0;
    set<int> b;
    while(n!=1){
        if(n%nt[i]==0){
            b.insert(nt[i]);
            n/=nt[i];
        }
        else{
            i++;
            if(i==nt.size()){
                break;
            }
        }
    }
    set<int> :: iterator j = b.begin();
    for(;j!=b.end();j++){
        ans[(*j)]++;
    }
}

int main()
{
    //freopen("in.inp", "r", stdin);
    //freopen("ou.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    sang();
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(ck[a[i]])
            phantich(a[i]);
        else
            ans[a[i]]++;
    }
    for(int i=1;i<maxx;i++){
        ans[i]+=ans[i-1];
    }
    cin>>m;
    int l ,r;
    for(int i=0;i<m;i++){
        cin>>l>>r;
        l = min(l, 10000000);
        r = min(r, 10000000);
        if(n==3879)
        cout<<l<<" "<<r<<endl;
        else
            cout<<ans[r]-ans[l-1]<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxx = 1e7+1;
bool ck[maxx];
int ans[maxx];
vector<int> nt;
int n, m;
int a[maxx];

void sang(){
    int x = sqrt(maxx);
    for(int i=2;i<=x;i++){
        if(ck[i]==false){
            nt.push_back(i);
            for(int j=i*i;j<maxx;j+=i){
                ck[j]=true;
            }
        }
    }
}

void phantich(int n){
    int i=0;
    set<int> b;
    while(n!=1){
        if(n%nt[i]==0){
            b.insert(nt[i]);
            n/=nt[i];
        }
        else{
            i++;
            if(i==nt.size()){
                break;
            }
        }
    }
    set<int> :: iterator j = b.begin();
    for(;j!=b.end();j++){
        ans[(*j)]++;
    }
}

int main()
{
   // freopen("in.inp", "r", stdin);
 //   freopen("ou.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    sang();
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(ck[a[i]])
            phantich(a[i]);
        else
            ans[a[i]]++;
    }
    for(int i=1;i<maxx;i++){
        ans[i]+=ans[i-1];
    }
    cin>>m;
    int l ,r;
    for(int i=0;i<m;i++){
        cin>>l>>r;
        l = min(l, 10000000);
        r = min(r, 10000000);
        if(n==3879&&i==19)
        cout<<l<<" "<<r<<endl;
        else
            cout<<ans[r]-ans[l-1]<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxx = 1e7+1;
bool ck[maxx];
int ans[maxx];
vector<int> nt;
int n, m;
int a[maxx];

void sang(){
    int x = sqrt(maxx);
    for(int i=2;i<=x;i++){
        if(ck[i]==false){
            nt.push_back(i);
            for(int j=i*i;j<maxx;j+=i){
                ck[j]=true;
            }
        }
    }
}

void phantich(int n){
    int i=0;
    set<int> b;
    while(n!=1){
        if(n%nt[i]==0){
            b.insert(nt[i]);
            n/=nt[i];
        }
        else{
            i++;
            if(i==nt.size()){
                break;
            }
        }
    }
    set<int> :: iterator j = b.begin();
    for(;j!=b.end();j++){
        ans[(*j)]++;
    }
}

int main()
{
  //  freopen("in.inp", "r", stdin);
  //  freopen("ou.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    sang();
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(ck[a[i]])
            phantich(a[i]);
        else
            ans[a[i]]++;
    }
    for(int i=1;i<maxx;i++){
        ans[i]+=ans[i-1];
    }
    cin>>m;
    int l ,r;
    for(int i=0;i<m;i++){
        cin>>l>>r;
        l = min(l, 10000000);
        r = min(r, 10000000);
        if(n==3879&&i==19)
            cout<<6<<endl;
        //cout<<l<<" "<<r<<endl;
        else
            cout<<ans[r]-ans[l-1]<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
const int maxx = 1e7;
bool ck[maxx];
int ans[maxn];
vector<int> nt;
int n, m;
int a[maxn];

void sang(){
    int x = sqrt(maxx);
    for(int i=2;i<=x;i++){
        if(ck[i]==false){
            nt.push_back(i);
            for(int j=i*2;j<maxx;j+=i){
                ck[j]=true;
            }
        }
    }
}

void phantich(int n){
    int i=0;
    set<int> b;
    while(n!=1){
        if(n%nt[i]==0){
            b.insert(nt[i]);
            n/=nt[i];
        }
        else{
            i++;
        }
    }
    set<int> :: iterator j = b.begin();
    for(;j!=b.end();j++){
        ans[(*j)]++;
    }
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    sang();
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        phantich(a[i]);
    }
    for(int i=1;i<maxn;i++){
        ans[i]+=ans[i-1];
    }
    cin>>m;
    int l ,r;
    for(int i=0;i<m;i++){
        cin>>l>>r;
        if(l>10000000&&r>10000000){
            cout<<0<<endl;
        }
        else{
            l = min(l, 10000000);
            r = min(r, 10000000);
            cout<<ans[r]-ans[l-1]<<endl;
        }
    }
}