#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define rev(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define si set<int>
#define sll set<ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007
#define endl '\n'
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
int n,m,k;
vpii fs;
vi ltc,lt,rtc,rt;
int main(){
    FIO;
    cin>>n>>m>>k;
    rep(i,1,n){
        int x;cin>>x;
        fs.pb(mp(x,1));
    }
    rep(i,1,m){
        int x;cin>>x;
        fs.pb(mp(x,2));
    }
    sort(fs.begin(),fs.end());
    fs.pb(mp(0,0));
    int st=1;
    rep(i,0,fs.size()-2){
        while(fs[i].F==fs[i+1].F) fs[i].F=st,i++;
        fs[i].F=st;
        st++;
    }
    rep(i,0,fs.size()-2){
        int cl=0,cr=0;
        while(fs[i].F==fs[i+1].F){
            if(fs[i].S==1) cl++;
            else cr++;
            i++;
        }
        if(fs[i].S==1) cl++;
        else cr++;
        if(cl>cr){
            ltc.pb(cl-cr);
            lt.pb(fs[i].F);
        }
        if(cr>cl){
            rtc.pb(cr-cl);
            rt.pb(fs[i].F);
        }
    }
    if(lt.size()==0){
        cout<<"NO";
        return 0;
    }
    int p1=lt.size()-1,p2=rt.size()-1;
    while(1){
        if(lt[p1]>rt[p2]){
            cout<<"YES";
            return 0;
        }
        int ct=0;
        while(p2>=0&&rt[p2]>lt[p1]) ct+=rtc[p2],p2--;
        if(ct<ltc[p1]){
            cout<<"YES";
            return 0;
        }
        else if(ct==ltc[p1]){
            p1--;
            if(p1==-1){
                cout<<"NO";
                return 0;
            }
            if(p2==-1){
                cout<<"YES";
                return 0;
            }
        }
        else{
            p1--;
            if(p1==-1){
                cout<<"NO";
                return 0;
            }
            p2++;
            rt[p2]=lt[p1+1];
            rtc[p2]=ct-ltc[p1+1];
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int n,m,k,x,p,r;
map<int,int> a;
int main()
{
	cin>>n>>m>>k;
	for (int i=0;i<n;i++) scanf("%d",&x),a[-x]++;
	for (int i=0;i<m;i++) scanf("%d",&x),a[-x]--;
	for (auto i:a) p+=i.second,r|=p>0;
	if (r) cout<<"YES";
	else cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
int n,m,k,x,p,r;
map<int,int> a;
int main()
{
	cin>>n>>m>>k;
	for (int i=0;i<n;i++) scanf("%d",&x),a[x]++;
	for (int i=0;i<m;i++) scanf("%d",&x),a[x]--;
	for (auto i:a) p+=i.second,r|=p>0;
	if (r) cout<<"YES";
	else cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
int x,n,m,k;
map<int,int>mp;
int main(){
	cin>>n>>m>>k;
	for(int i=0;i<n;i++)cin>>x,mp[-x]++;
	for(int i=0;i<m;i++)cin>>x,mp[-x]--;
	int ps=0;
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
		ps+=it->second;
		if(ps>0){
			cout<<"YES";
			return 0;
		}
	}
	cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
int x,n,m,k;
map<int,int>mp;
int main(){
	cin>>n>>m>>k;
	for(int i=0;i<n;i++)cin>>x,mp[-x]++;
	for(int i=0;i<m;i++)cin>>x,mp[-x]--;
	int ps=0;
	for(typeof(mp.begin())it=mp.begin();it!=mp.end();it++){
		ps+=it->second;
		if(ps>0){
			cout<<"YES";
			return 0;
		}
	}
	cout<<"NO";
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin64b
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

/*class TaskE {
private:
    vector<int> cnts;

    int64_t calcCnt(int cur, int mid) {
        if (cur / 2 < mid) {
            return 1;
        }

        if (memo.find({cur, mid}) != memo.end()) {
            return memo[{cur, mid}];
        }

        if (cur % 2 == 1) {
            memo[{cur, mid}] = calcCnt(cur / 2, mid) + calcCnt(cur / 2 + 1, mid);
        } else {
            memo[{cur, mid}] = calcCnt(cur / 2, mid) * 2;
        }

        return memo[{cur, mid}];

        int64_t cnt = 1;
        if (cur % 2 == 1 && mid % 2 == 1) {
            while (cur / 2 >= mid) {
                cur /= 2;
                cnt *= 2;
            }
            if (cur / 2 + 1 >= mid) {
                cnt *= 2;
            }
        } else {
            while (cur / 2 >= mid) {
                cur /= 2;
                cnt *= 2;
            }
        }
        return cnt;

        int64_t cnt = 1;
        while (cur / 2 >= mid) {
            cur /= 2;
            cnt *= 2;
        }
        return cnt;
    }
public:
    void solve(istream& in, ostream& out) {
        cnts.assign(1e7+1, 0);

        int n, k;
        in >> n >> k;

        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            in >> a[i];
            ++cnts[a[i]];
        }

        //sort(a.begin(), a.end(), greater<int>());

        int64_t cnt = 0;
        for (size_t i = 0; i < a.size(); ++i) {
            cnt += a[i];
            //out << a[i] << " : " << calcCnt(a[i], 1) << endl;
        }
        if (cnt < k) {
            out << -1 << endl;
            return;
        }

        int low = 1, high = 1e7 + 1;
        while (low <= high) {

            //cout << low << " " << high << endl;
            //cin.get();
            int mid = (low + high) / 2;
            cnt = 0;
            for (size_t i = 0; i < a.size(); ++i) {
                if (a[i] < mid) continue;

                cnt += calcCnt(a[i], mid);
                //out << a[i] << "," << mid << " : " << calcCnt(a[i], mid) << endl;

            }
            if (cnt < k) {
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }
        out << low - 1 << endl;
    }
};*/

class TaskE {
public:
    void solve(istream& in, ostream& out) {
        int n, k;
        in >> n >> k;

        //map<int,int> parts;
        int sz = 1e7 + 1;
        vector<int64_t> parts(sz, 0);
        vector<int> a(n);
        int64_t cnt = 0;
        for (int i = 0; i < n; ++i) {
            in >> a[i];
            parts[a[i]]++;
            cnt += a[i];
        }

        if (cnt < k) {
            out << -1 << endl;
            return;
        }

        int sm = 0, big = sz - 1;

        while (sm < big) {
            while (sm < big && !parts[sm]) {
                ++sm;
            }
            while (big >= sm && !parts[big]) {
                --big;
            }
            while (n > k) {
                int64_t save = parts[sm], diff = n - k;
                parts[sm] = max(save - diff, 0LL);
                n -= (save - parts[sm]);
                //cout << "remove " << save - parts[sm] << " of " << sm << " -> " << n << endl;
                //cin.get();
                while (sm < sz && !parts[sm]) {
                    ++sm;
                }
            }

            if (big <= 1) {
                break;
            }

            int v1 = big / 2, v2 = big / 2 + (big % 2);

            if (n < k) {
                //cout << "1erase " << big << " and add " << v2 << " " << v1 << " mit " << parts[big] << endl;

                parts[v1] += parts[big];
                parts[v2] += parts[big];
                n += parts[big];
                sm = min(sm, v1);
                parts[big] = 0;
                --big;
            } else if (v2 > sm) {
                //cout << "2erase " << big << " and add " << v2 << " " << v1 << " mit " << parts[big] << endl;

                parts[v1] += parts[big];
                parts[v2] += parts[big];
                parts[big] = 0;
                n += parts[big];
                --big;
            } else {
                break;
            }

            //cout << sm << " " << big << endl;
            /*while (n > k) {
                int save = parts[parts.begin()->first], diff = n - k;
                parts[parts.begin()->first] = max(save - diff, 0);
                n -= (save - parts[parts.begin()->first]);
                if (parts[parts.begin()->first] == 0) {
                    parts.erase(parts.begin());
                }
            }

            pair<int,int> sm = *parts.begin(), big = *parts.rbegin();

            if (big.first <= 1) {
                break;
            }
            int v1 = big.first / 2, v2 = big.first / 2;
            if (big.first % 2 == 1) {
                ++v2;
            }
            //out << "size: " << parts.size() << endl;
            if (n < k) {
                //out << "erase " << parts.rbegin()->first << " and add " << v2 << " " << v1 << " mit " << big.second << endl;
                parts.erase(--parts.end());
                parts[v2] += big.second;
                parts[v1] += big.second;
                n += big.second;

            } else if (v2 > sm.first) {
                //out << "erase " << parts.rbegin()->first << " and add " << v2 << " " << v1 << " mit " << big.second << endl;
                //out << "because v2 is bigger than " << sm.first << endl;
                parts.erase(--parts.end());
                //parts.erase(parts.begin());
                parts[v2] += big.second;
                parts[v1] += big.second;
                n += big.second;

            } else {
                break;
            }
            //out << n << endl;
            */

        }
        //out << sm << " " << big << endl;

        out << sm << endl;

    }
};

int main() {
	std::ios::sync_with_stdio(false);

	TaskE solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin64b
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

class TaskE {
public:
    void solve(istream& in, ostream& out) {
        int n, k;
        in >> n >> k;
        //cout << "hi" << endl;
        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            in >> a[i];
        }
        //cout << "hi" << endl;
        sort(a.begin(), a.end(), greater<int>());
        //cout << "hi" << endl;
        int64_t cnt = 0;
        for (size_t i = 0; i < a.size(); ++i) {
            int64_t cur = a[i], tmpcnt = 1;
            while (cur / 2 >= 1) {
                //out << cur << " ";
                tmpcnt *= 2;
                cur /= 2;
            }
            //out << endl;
            cnt += tmpcnt;
        }
        if (cnt < k) {
            out << -1 << endl;
            return;
        }
        //cout << "hi" << endl;

        int low = 1, high = 1e7;
        while (low < high) {
            //cout << low << " " << high << endl;
            //cin.get();
            int mid = (low + high + 1) / 2;
            cnt = 0;
            for (size_t i = 0; i < a.size(); ++i) {
                if (a[i] < mid) continue;

                int64_t cur = a[i], tmpcnt = 1;
                while (cur / 2 >= mid) {
                    tmpcnt *= 2;
                    cur /= 2;
                }
                cnt += tmpcnt;
            }
            if (cnt < k) {
                high = mid - 1;
            } else {
                //if (low == mid) break;
                low = mid;
            }
        }
        out << low << endl;
    }
};

int main() {
	std::ios::sync_with_stdio(false);

	TaskE solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin64b
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

/*class TaskE {
private:
    vector<int> cnts;

    int64_t calcCnt(int cur, int mid) {
        if (cur / 2 < mid) {
            return 1;
        }

        if (memo.find({cur, mid}) != memo.end()) {
            return memo[{cur, mid}];
        }

        if (cur % 2 == 1) {
            memo[{cur, mid}] = calcCnt(cur / 2, mid) + calcCnt(cur / 2 + 1, mid);
        } else {
            memo[{cur, mid}] = calcCnt(cur / 2, mid) * 2;
        }

        return memo[{cur, mid}];

        int64_t cnt = 1;
        if (cur % 2 == 1 && mid % 2 == 1) {
            while (cur / 2 >= mid) {
                cur /= 2;
                cnt *= 2;
            }
            if (cur / 2 + 1 >= mid) {
                cnt *= 2;
            }
        } else {
            while (cur / 2 >= mid) {
                cur /= 2;
                cnt *= 2;
            }
        }
        return cnt;

        int64_t cnt = 1;
        while (cur / 2 >= mid) {
            cur /= 2;
            cnt *= 2;
        }
        return cnt;
    }
public:
    void solve(istream& in, ostream& out) {
        cnts.assign(1e7+1, 0);

        int n, k;
        in >> n >> k;

        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            in >> a[i];
            ++cnts[a[i]];
        }

        //sort(a.begin(), a.end(), greater<int>());

        int64_t cnt = 0;
        for (size_t i = 0; i < a.size(); ++i) {
            cnt += a[i];
            //out << a[i] << " : " << calcCnt(a[i], 1) << endl;
        }
        if (cnt < k) {
            out << -1 << endl;
            return;
        }

        int low = 1, high = 1e7 + 1;
        while (low <= high) {

            //cout << low << " " << high << endl;
            //cin.get();
            int mid = (low + high) / 2;
            cnt = 0;
            for (size_t i = 0; i < a.size(); ++i) {
                if (a[i] < mid) continue;

                cnt += calcCnt(a[i], mid);
                //out << a[i] << "," << mid << " : " << calcCnt(a[i], mid) << endl;

            }
            if (cnt < k) {
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }
        out << low - 1 << endl;
    }
};*/

class TaskE {
public:
    void solve(istream& in, ostream& out) {
        int n, k;
        in >> n >> k;

        map<int,int> parts;
        vector<int> a(n);
        int64_t cnt = 0;
        for (int i = 0; i < n; ++i) {
            in >> a[i];
            parts[a[i]]++;
            cnt += a[i];
        }

        if (cnt < k) {
            out << -1 << endl;
            return;
        }

        while (!parts.empty()) {
            while (n > k) {
                int save = parts[parts.begin()->first], diff = n - k;
                parts[parts.begin()->first] = max(save - diff, 0);
                n -= (save - parts[parts.begin()->first]);
                if (parts[parts.begin()->first] == 0) {
                    parts.erase(parts.begin());
                }
            }

            pair<int,int> sm = *parts.begin(), big = *parts.rbegin();

            if (big.first <= 1) {
                break;
            }
            int v1 = big.first / 2, v2 = big.first / 2;
            if (big.first % 2 == 1) {
                ++v2;
            }
            //out << "size: " << parts.size() << endl;
            if (n < k) {
                //out << "erase " << parts.rbegin()->first << " and add " << v2 << " " << v1 << " mit " << big.second << endl;
                parts.erase(--parts.end());
                parts[v2] += big.second;
                parts[v1] += big.second;
                n += big.second;

            } else if (v2 > sm.first) {
                //out << "erase " << parts.rbegin()->first << " and add " << v2 << " " << v1 << " mit " << big.second << endl;
                //out << "because v2 is bigger than " << sm.first << endl;
                parts.erase(--parts.end());
                //parts.erase(parts.begin());
                parts[v2] += big.second;
                parts[v1] += big.second;
                n += big.second;

            } else {
                break;
            }
            //out << n << endl;
        }

        if (n < k) {
            out << -1 << endl;
        } else {
            out << parts.begin()->first << endl;
        }
    }
};

int main() {
	std::ios::sync_with_stdio(false);

	TaskE solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin64b
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

/*class TaskE {
private:
    vector<int> cnts;

    int64_t calcCnt(int cur, int mid) {
        if (cur / 2 < mid) {
            return 1;
        }

        if (memo.find({cur, mid}) != memo.end()) {
            return memo[{cur, mid}];
        }

        if (cur % 2 == 1) {
            memo[{cur, mid}] = calcCnt(cur / 2, mid) + calcCnt(cur / 2 + 1, mid);
        } else {
            memo[{cur, mid}] = calcCnt(cur / 2, mid) * 2;
        }

        return memo[{cur, mid}];

        int64_t cnt = 1;
        if (cur % 2 == 1 && mid % 2 == 1) {
            while (cur / 2 >= mid) {
                cur /= 2;
                cnt *= 2;
            }
            if (cur / 2 + 1 >= mid) {
                cnt *= 2;
            }
        } else {
            while (cur / 2 >= mid) {
                cur /= 2;
                cnt *= 2;
            }
        }
        return cnt;

        int64_t cnt = 1;
        while (cur / 2 >= mid) {
            cur /= 2;
            cnt *= 2;
        }
        return cnt;
    }
public:
    void solve(istream& in, ostream& out) {
        cnts.assign(1e7+1, 0);

        int n, k;
        in >> n >> k;

        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            in >> a[i];
            ++cnts[a[i]];
        }

        //sort(a.begin(), a.end(), greater<int>());

        int64_t cnt = 0;
        for (size_t i = 0; i < a.size(); ++i) {
            cnt += a[i];
            //out << a[i] << " : " << calcCnt(a[i], 1) << endl;
        }
        if (cnt < k) {
            out << -1 << endl;
            return;
        }

        int low = 1, high = 1e7 + 1;
        while (low <= high) {

            //cout << low << " " << high << endl;
            //cin.get();
            int mid = (low + high) / 2;
            cnt = 0;
            for (size_t i = 0; i < a.size(); ++i) {
                if (a[i] < mid) continue;

                cnt += calcCnt(a[i], mid);
                //out << a[i] << "," << mid << " : " << calcCnt(a[i], mid) << endl;

            }
            if (cnt < k) {
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }
        out << low - 1 << endl;
    }
};*/

class TaskE {
public:
    void solve(istream& in, ostream& out) {
        int n, k;
        in >> n >> k;

        //map<int,int> parts;
        int sz = 1e7 + 1;
        vector<int64_t> parts(sz, 0);
        vector<int> a(n);
        int64_t cnt = 0;
        for (int i = 0; i < n; ++i) {
            in >> a[i];
            parts[a[i]]++;
            cnt += a[i];
        }

        if (cnt < k) {
            out << -1 << endl;
            return;
        }

        int sm = 0, big = sz - 1;

        while (sm < big) {
            while (sm < big && !parts[sm]) {
                ++sm;
            }
            while (big >= sm && !parts[big]) {
                --big;
            }
            while (n > k) {
                int64_t save = parts[sm], diff = n - k;
                parts[sm] = max(save - diff, 0LL);
                n -= (save - parts[sm]);
                cout << "remove " << save - parts[sm] << " of " << sm << " -> " << n << endl;
                //cin.get();
                while (sm < sz && !parts[sm]) {
                    ++sm;
                }
            }

            if (big <= 1) {
                break;
            }

            int v1 = big / 2, v2 = big / 2 + (big % 2);
            //cout << n << " -> ";
            if (n < k) {
                //cout << "1erase " << big << " and add " << v2 << " " << v1 << " mit " << parts[big] << endl;

                parts[v1] += parts[big];
                parts[v2] += parts[big];
                n += parts[big];
                sm = min(sm, v1);
                parts[big] = 0;
                --big;
            } else if (v2 > sm) {
                //cout << "2erase " << big << " and add " << v2 << " " << v1 << " mit " << parts[big] << endl;

                parts[v1] += parts[big];
                parts[v2] += parts[big];
                n += parts[big];

                parts[big] = 0;
                --big;
            } else {
                break;
            }
            //cout << n << endl;
            //cout << sm << " " << big << endl;
            /*while (n > k) {
                int save = parts[parts.begin()->first], diff = n - k;
                parts[parts.begin()->first] = max(save - diff, 0);
                n -= (save - parts[parts.begin()->first]);
                if (parts[parts.begin()->first] == 0) {
                    parts.erase(parts.begin());
                }
            }

            pair<int,int> sm = *parts.begin(), big = *parts.rbegin();

            if (big.first <= 1) {
                break;
            }
            int v1 = big.first / 2, v2 = big.first / 2;
            if (big.first % 2 == 1) {
                ++v2;
            }
            //out << "size: " << parts.size() << endl;
            if (n < k) {
                //out << "erase " << parts.rbegin()->first << " and add " << v2 << " " << v1 << " mit " << big.second << endl;
                parts.erase(--parts.end());
                parts[v2] += big.second;
                parts[v1] += big.second;
                n += big.second;

            } else if (v2 > sm.first) {
                //out << "erase " << parts.rbegin()->first << " and add " << v2 << " " << v1 << " mit " << big.second << endl;
                //out << "because v2 is bigger than " << sm.first << endl;
                parts.erase(--parts.end());
                //parts.erase(parts.begin());
                parts[v2] += big.second;
                parts[v1] += big.second;
                n += big.second;

            } else {
                break;
            }
            //out << n << endl;
            */

        }
        //out << sm << " " << big << endl;

        out << sm << endl;

    }
};

int main() {
	std::ios::sync_with_stdio(false);

	TaskE solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin64b
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

class TaskE {
public:
    void solve(istream& in, ostream& out) {
        int n, k;
        in >> n >> k;

        //priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>()> smallest;
        //priority_queue<pair<int,int>> biggest;
        multiset<pair<int,int>> parts;
        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            in >> a[i];
            //smallest.push({a[i], i});
            //biggest.push({a[i], i});
            parts.insert({a[i], i});
        }

        while ((int)parts.size() > k) {
            parts.erase(parts.begin());
        }

        while (!parts.empty()) {
            pair<int,int> sm = *parts.begin(), big = *parts.rbegin();

            if (big.first <= 1) {
                break;
            }
            int v1 = big.first / 2, v2 = big.first / 2;
            if (big.first % 2 == 1) {
                ++v2;
            }
            //out << "size: " << parts.size() << endl;
            if ((int)parts.size() < k) {
                //out << "erase " << parts.rbegin()->first << " and add " << v2 << " " << v1 << endl;
                parts.erase(--parts.end());
                parts.insert({v2, big.second});
                parts.insert({v1, big.second});
            } else if (v2 > sm.first) {
                //out << "erase " << parts.rbegin()->first << " " << parts.begin()->first << " and add " << v2 << " " << v1 << endl;
                //out << "because v2 is bigger than " << sm.first << endl;
                parts.erase(--parts.end());
                parts.erase(parts.begin());
                parts.insert({v2, big.second});
                parts.insert({v1, big.second});
            } else {
                break;
            }
        }

        if ((int)parts.size() < k) {
            out << -1 << endl;
        } else {
            out << parts.begin()->first << endl;
        }
    }
};

int main() {
	std::ios::sync_with_stdio(false);

	TaskE solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin64b
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

class TaskE {
public:
    void solve(istream& in, ostream& out) {
        int n, k;
        in >> n >> k;
        //cout << "hi" << endl;
        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            in >> a[i];
        }
        //cout << "hi" << endl;
        sort(a.begin(), a.end(), greater<int>());
        //cout << "hi" << endl;
        int64_t cnt = 0;
        for (size_t i = 0; i < a.size(); ++i) {
            int64_t cur = a[i], tmpcnt = 1;
            while (cur / 2 >= 1) {
                //out << cur << " ";
                tmpcnt *= 2;
                cur /= 2;
            }
            //out << endl;
            cnt += tmpcnt;
        }
        if (cnt < k) {
            out << -1 << endl;
            return;
        }
        //cout << "hi" << endl;

        int low = 1, high = 1e7 + 1;
        while (low <= high) {
            //cout << low << " " << high << endl;
            //cin.get();
            int mid = (low + high) / 2;
            cnt = 0;
            for (size_t i = 0; i < a.size(); ++i) {
                if (a[i] < mid) continue;

                int64_t cur = a[i], tmpcnt = 1;
                while (cur / 2 >= mid) {
                    tmpcnt *= 2;
                    cur /= 2;
                }
                cnt += tmpcnt;
            }
            if (cnt < k) {
                high = mid - 1;
            } else {
                //if (low == mid) break;
                low = mid + 1;
            }
        }
        out << low - 1 << endl;
    }
};

int main() {
	std::ios::sync_with_stdio(false);

	TaskE solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


// Smile please :)

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <climits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

//#undef KVARK_DEBUG

#ifdef KVARK_DEBUG
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x, y) cout << #x << " = " << x << "; " << #y << " = " << y << endl
#else
#define dbg(...) (void(1));
#define dbg2(...) (void(1));
#endif

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<pii> > vvpii;
typedef vector<vector<long long> > vvl;
typedef vector<long long> vl;
typedef long long int llint;

#define ALL(v) (v.begin()), (v.end())
#define SZ(v) ((int)((v).size()))
#define endl "\n"

void task();

int main(){
#ifdef KVARK
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	srand(time(0));
#endif
//	ios_base::sync_with_stdio(0);

	task();

	return 0;
}
const int INF = 0x3f3f3f3f;
const int N = 1e6+10;
const int M = 1e7+100;

int n, k;
int a[N];
llint dp[M];

int solve(int m) {
	memset(dp, 0, m * sizeof(llint));
	for (int i = m; i < M; ++i) {
		dp[i] = max(1LL, dp[i/2] + dp[i - i/2]);
	}
	llint yet = k;
	for (int i = 0; i < n; ++i) {
		yet -= dp[a[i]];
		if (yet <= 0)
			return 1;
	}
	return 0;
}

void task(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	reverse(a, a + n);
	int l = 1;
	int r = 1e7+100;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (solve(mid)) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	if (l == 0)
		cout << -1;
	else
		cout << l;
}


// Smile please :)

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <climits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

//#undef KVARK_DEBUG

#ifdef KVARK_DEBUG
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x, y) cout << #x << " = " << x << "; " << #y << " = " << y << endl
#else
#define dbg(...) (void(1));
#define dbg2(...) (void(1));
#endif

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<pii> > vvpii;
typedef vector<vector<long long> > vvl;
typedef vector<long long> vl;
typedef long long int llint;

#define ALL(v) (v.begin()), (v.end())
#define SZ(v) ((int)((v).size()))
#define endl "\n"

void task();

int main(){
#ifdef KVARK
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	srand(time(0));
#endif
//	ios_base::sync_with_stdio(0);

	task();

	return 0;
}
const int INF = 0x3f3f3f3f;
const int N = 1e6+10;
const int M = 1e7+100;

int n, k;
int a[N];
llint dp[M];

int solve(int m) {
	memset(dp, 0, m * sizeof(llint));
	for (int i = m; i < M; ++i) {
		dp[i] = max(1LL, dp[i/2] + dp[i - i/2]);
	}
	llint yet = k;
	for (int i = 0; i < n; ++i) {
		yet -= dp[a[i]];
		if (yet <= 0)
			return 1;
	}
	return 0;
}

void task(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	reverse(a, a + n);
	int l = 1;
	int r = 1e7+100;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (solve(mid)) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	int ans = -1;
	for (int i = max(1, l-3); i < l+3; ++i) {
		if (solve(i)) {
			ans = i;
		}
	}
	cout << ans;
}


// Smile please :)

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <climits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

//#undef KVARK_DEBUG

#ifdef KVARK_DEBUG
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x, y) cout << #x << " = " << x << "; " << #y << " = " << y << endl
#else
#define dbg(...) (void(1));
#define dbg2(...) (void(1));
#endif

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<pii> > vvpii;
typedef vector<vector<long long> > vvl;
typedef vector<long long> vl;
typedef long long int llint;

#define ALL(v) (v.begin()), (v.end())
#define SZ(v) ((int)((v).size()))
#define endl "\n"

void task();

int main(){
#ifdef KVARK
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	srand(time(0));
#endif
//	ios_base::sync_with_stdio(0);

	task();

	return 0;
}
const int INF = 0x3f3f3f3f;
const int N = 1e6+10;
const int M = 3e5+10;

int n, k;
int a[N];

int solve(int m) {
	if (m <= 0) {
		return 0;
	}
	int yet = k;
	for (int i = 0; i < n; ++i) {
		int add = a[i] / m;
		yet -= add;
		if (yet <= 0) {
			return 1;
		}
	}
	return 0;
}

void task(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	int l = 1;
	int r = 1e7+100;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (solve(mid)) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	int ans = -1;
	for (int i = max(1, l-3); i < l+3; ++i) {
		if (solve(i)) {
			ans = i;
		}
	}
	cout << ans;
}


// Smile please :)

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <climits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

//#undef KVARK_DEBUG

#ifdef KVARK_DEBUG
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x, y) cout << #x << " = " << x << "; " << #y << " = " << y << endl
#else
#define dbg(...) (void(1));
#define dbg2(...) (void(1));
#endif

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<pii> > vvpii;
typedef vector<vector<long long> > vvl;
typedef vector<long long> vl;
typedef long long int llint;

#define ALL(v) (v.begin()), (v.end())
#define SZ(v) ((int)((v).size()))
#define endl "\n"

void task();

int main(){
#ifdef KVARK
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	srand(time(0));
#endif
//	ios_base::sync_with_stdio(0);

	task();

	return 0;
}
const int INF = 0x3f3f3f3f;
const int N = 1e6+10;
const int M = 3e5+10;

int n, k;
map<int, int> a;
vpii aa;

int cnt(int n, int m);

int cnt(int n1, int n2, int cnt1, int cnt2, int m) {
	if (m > n1 || cnt1 == 0) {
		return cnt2 * cnt(n2, m);
	}
	if (m > n2 || cnt2 == 0) {
		return cnt1 * cnt(n1, m);
	}
	if (n1 / 2 < m) {
		return cnt1 + cnt2 * cnt(n2, m);
	}
	if (n2 / 2 < m) {
		return cnt2 + cnt1 * cnt(n1, m);
	}
	int mn = n1 / 2;
	int mx = n2 - n2 / 2;
	if (mn == mx) {
		return 4 * (cnt1 + cnt2) * cnt(n1/2, m);
	}
	int cntmn = cnt1*(n1/2 == mn) + cnt1*((n1 - n1/2) == mn) + cnt2*(n2/2==mn) + cnt2*((n2 - n2/2) == mn);
	int cntmx = (cnt1+cnt2)*2 - cntmn;
	return cnt(mn, mx, cntmn, cntmx, m);
}

int cnt(int n, int m) {
	if (m > n) {
		return 0;
	}
	if (n / 2 < m) {
		return 1;
	}
	if (n % 2 == 0) {
		return 2 * cnt(n / 2, m);
	} else {
		return cnt(n/2, n/2+1, 1, 1, m);
	}
}

int solve(int m) {
	if (m <= 0) {
		return 0;
	}
	llint yet = k;
	for (pii& p: aa) {
		llint add = cnt(p.first, m) * (llint)p.second;
		yet -= add;
		if (yet <= 0) {
			return 1;
		}
	}
	return 0;
}

void task(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i) {
		int x;
		scanf("%d", &x);
		a[x]++;
	}
	for (pii p: a) {
		aa.push_back(p);
	}
	int l = 1;
	int r = 1e7+100;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (solve(mid)) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	int ans = -1;
	for (int i = max(1, l-3); i < l+3; ++i) {
		if (solve(i)) {
			ans = i;
		}
	}
	cout << ans;
}


// Smile please :)

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <climits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

//#undef KVARK_DEBUG

#ifdef KVARK_DEBUG
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x, y) cout << #x << " = " << x << "; " << #y << " = " << y << endl
#else
#define dbg(...) (void(1));
#define dbg2(...) (void(1));
#endif

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<pii> > vvpii;
typedef vector<vector<long long> > vvl;
typedef vector<long long> vl;
typedef long long int llint;

#define ALL(v) (v.begin()), (v.end())
#define SZ(v) ((int)((v).size()))
#define endl "\n"

void task();

int main(){
#ifdef KVARK
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	srand(time(0));
#endif
//	ios_base::sync_with_stdio(0);

	task();

	return 0;
}
const int INF = 0x3f3f3f3f;
const int N = 1e6+10;
const int M = 1e7+100;

int n, k;
int a[N];
llint dp[M];

int solve(int m) {
	int mm = min(M, m+10);
	memset(dp, 0, mm * sizeof(llint));
	for (int i = m; i < M; ++i) {
		dp[i] = max(1LL, dp[i/2] + dp[i - i/2]);
	}
	llint yet = k;
	for (int i = 0; i < n; ++i) {
		yet -= dp[a[i]];
		if (yet <= 0)
			return 1;
	}
	return 0;
}

void task(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	reverse(a, a + n);
	int l = 1;
	int r = 1e7+100;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (solve(mid)) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	if (l == 0)
		cout << -1;
	else
		cout << l;
}


// Smile please :)

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <climits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

//#undef KVARK_DEBUG

#ifdef KVARK_DEBUG
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x, y) cout << #x << " = " << x << "; " << #y << " = " << y << endl
#else
#define dbg(...) (void(1));
#define dbg2(...) (void(1));
#endif

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<pii> > vvpii;
typedef vector<vector<long long> > vvl;
typedef vector<long long> vl;
typedef long long int llint;

#define ALL(v) (v.begin()), (v.end())
#define SZ(v) ((int)((v).size()))
#define endl "\n"

void task();

int main(){
#ifdef KVARK
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	srand(time(0));
#endif
//	ios_base::sync_with_stdio(0);

	task();

	return 0;
}
const int INF = 0x3f3f3f3f;
const int N = 1e6+10;
const int M = 1e7+100;

int n, k;
int a[N];
llint dp[M];

int solve(int m) {
	memset(dp, 0, sizeof(dp));
	for (int i = 1; i < M; ++i) {
		if (i >= m) {
			dp[i] = 1;
		}
		if (i / 2 >= m) {
			dp[i] = max(dp[i], dp[i/2] + dp[i - i/2]);
		} else if (i - i / 2 >= m) {
			dp[i] = max(dp[i], dp[i - i/2]);
		}
	}
	llint yet = k;
	for (int i = 0; i < n; ++i) {
		yet -= dp[a[i]];
		if (yet <= 0)
			return 1;
	}
	return 0;
}

void task(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	int l = 1;
	int r = 1e7+100;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (solve(mid)) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	int ans = -1;
	for (int i = max(1, l-3); i < l+3; ++i) {
		if (solve(i)) {
			ans = i;
		}
	}
	cout << ans;
}


// Smile please :)

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <climits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

//#undef KVARK_DEBUG

#ifdef KVARK_DEBUG
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x, y) cout << #x << " = " << x << "; " << #y << " = " << y << endl
#else
#define dbg(...) (void(1));
#define dbg2(...) (void(1));
#endif

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<pii> > vvpii;
typedef vector<vector<long long> > vvl;
typedef vector<long long> vl;
typedef long long int llint;

#define ALL(v) (v.begin()), (v.end())
#define SZ(v) ((int)((v).size()))
#define endl "\n"

void task();

int main(){
#ifdef KVARK
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	srand(time(0));
#endif
//	ios_base::sync_with_stdio(0);

	task();

	return 0;
}
const int INF = 0x3f3f3f3f;
const int N = 1e6+10;
const int M = 1e7+100;

int n, k;
int a[N];
llint dp[M];

int solve(int m) {
	memset(dp, 0, sizeof(dp));
	for (int i = 1; i < M; ++i) {
		if (i >= m) {
			dp[i] = 1;
		}
		if (i / 2 >= m) {
			dp[i] = dp[i/2] + dp[i - i/2];
		} else if (i - i / 2 >= m) {
			dp[i] = dp[i - i/2];
		}
	}
	llint yet = k;
	for (int i = 0; i < n; ++i) {
		yet -= dp[a[i]];
		if (yet <= 0)
			return 1;
	}
	return 0;
}

void task(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	int l = 1;
	int r = 1e7+100;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (solve(mid)) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	int ans = -1;
	for (int i = max(1, l-3); i < l+3; ++i) {
		if (solve(i)) {
			ans = i;
		}
	}
	cout << ans;
}


// Smile please :)

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <climits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

//#undef KVARK_DEBUG

#ifdef KVARK_DEBUG
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x, y) cout << #x << " = " << x << "; " << #y << " = " << y << endl
#else
#define dbg(...) (void(1));
#define dbg2(...) (void(1));
#endif

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<pii> > vvpii;
typedef vector<vector<long long> > vvl;
typedef vector<long long> vl;
typedef long long int llint;

#define ALL(v) (v.begin()), (v.end())
#define SZ(v) ((int)((v).size()))
#define endl "\n"

void task();

int main(){
#ifdef KVARK
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	srand(time(0));
#endif
//	ios_base::sync_with_stdio(0);

	task();

	return 0;
}
const int INF = 0x3f3f3f3f;
const int N = 1e6+10;
const int M = 3e5+10;

int n, k;
int a[N];

int cnt(int n, int m);

int cnt(int n1, int n2, int cnt1, int cnt2, int m) {
	if (m > n1) {
		return cnt2 * cnt(n2, m);
	}
	if (m > n2) {
		return cnt1 * cnt(n1, m);
	}
	if (n1 / 2 < m) {
		return cnt1 + cnt2 * cnt(n2, m);
	}
	if (n2 / 2 < m) {
		return cnt2 + cnt1 * cnt(n1, m);
	}
	int mn = n1/2;
	int mx = n2 - n2/2;
	int cntmn = (n1/2 == mn) + ((n1 - n1/2) == mn) + (n2/2==mn) + ((n2 - n2/2) == mn);
	int cntmx = 4 - cntmn;
	return cnt(mn, mx, cntmn, cntmx, m);
}

int cnt(int n, int m) {
	if (m > n) {
		return 0;
	}
	if (n % 2 == 0) {
		if (n / 2 < m) {
			return 1;
		}
		return 2 * cnt(n / 2, m);
	}
	if (n % 2 == 1) {
		if (n / 2 < m) {
			return 1;
		}
		return cnt(n/2, n/2+1, 1, 1, m);
	}
}

int solve(int m) {
	if (m <= 0) {
		return 0;
	}
	int yet = k;
	for (int i = 0; i < n; ++i) {
		int add = cnt(a[i], m);
		yet -= add;
		if (yet <= 0) {
			return 1;
		}
	}
	return 0;
}

void task(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	int l = 1;
	int r = 1e7+100;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (solve(mid)) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	int ans = -1;
	for (int i = max(1, l-3); i < l+3; ++i) {
		if (solve(i)) {
			ans = i;
		}
	}
	cout << ans;
}


// Smile please :)

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <climits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

//#undef KVARK_DEBUG

#ifdef KVARK_DEBUG
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x, y) cout << #x << " = " << x << "; " << #y << " = " << y << endl
#else
#define dbg(...) (void(1));
#define dbg2(...) (void(1));
#endif

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<pii> > vvpii;
typedef vector<vector<long long> > vvl;
typedef vector<long long> vl;
typedef long long int llint;

#define ALL(v) (v.begin()), (v.end())
#define SZ(v) ((int)((v).size()))
#define endl "\n"

void task();

int main(){
#ifdef KVARK
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	srand(time(0));
#endif
//	ios_base::sync_with_stdio(0);

	task();

	return 0;
}
const int INF = 0x3f3f3f3f;
const int N = 1e6+10;
const int M = 3e5+10;

int n, k;
int a[N];

int solve(int m) {
	int yet = k;
	for (int i = 0; i < n; ++i) {
		int add = a[i] / m;
		yet -= add;
		if (yet <= 0) {
			return 1;
		}
	}
	return 0;
}

void task(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	int l = 0;
	int r = 1e7+100;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (solve(mid)) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	int ans = -1;
	for (int i = max(1, l-2); i < l+2; ++i) {
		if (solve(i)) {
			ans = i;
		}
	}
	cout << ans;
}


// Smile please :)

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <climits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

//#undef KVARK_DEBUG

#ifdef KVARK_DEBUG
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x, y) cout << #x << " = " << x << "; " << #y << " = " << y << endl
#else
#define dbg(...) (void(1));
#define dbg2(...) (void(1));
#endif

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<pii> > vvpii;
typedef vector<vector<long long> > vvl;
typedef vector<long long> vl;
typedef long long int llint;

#define ALL(v) (v.begin()), (v.end())
#define SZ(v) ((int)((v).size()))
#define endl "\n"

void task();

int main(){
#ifdef KVARK
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	srand(time(0));
#endif
//	ios_base::sync_with_stdio(0);

	task();

	return 0;
}
const int INF = 0x3f3f3f3f;
const int N = 1e6+10;
const int M = 3e5+10;

int n, k;
map<int, int> a;
vpii aa;

int cnt(int n, int m);

int cnt(int n1, int n2, int cnt1, int cnt2, int m) {
	if (m > n1 || cnt1 == 0) {
		return cnt2 * cnt(n2, m);
	}
	if (m > n2 || cnt2 == 0) {
		return cnt1 * cnt(n1, m);
	}
	if (n1 / 2 < m) {
		return cnt1 + cnt2 * cnt(n2, m);
	}
	if (n2 / 2 < m) {
		return cnt2 + cnt1 * cnt(n1, m);
	}
	int mn = n1 / 2;
	int mx = n2 - n2 / 2;
	if (mn == mx) {
		return 4 * (cnt1 + cnt2) * cnt(n1/2, m);
	}
	int cntmn = cnt1*(n1/2 == mn) + cnt1*((n1 - n1/2) == mn) + cnt2*(n2/2==mn) + cnt2*((n2 - n2/2) == mn);
	int cntmx = (cnt1+cnt2)*2 - cntmn;
	return cnt(mn, mx, cntmn, cntmx, m);
}

int cnt(int n, int m) {
	if (m > n) {
		return 0;
	}
	if (n / 2 < m) {
		return 1;
	}
	if (n % 2 == 0) {
		return 2 * cnt(n / 2, m);
	} else {
		return cnt(n/2, n/2+1, 1, 1, m);
	}
}

int solve(int m) {
	if (m <= 0) {
		return 0;
	}
	llint yet = k;
	for (pii& p: aa) {
		llint add = cnt(p.first, m) * p.second;
		yet -= add;
		if (yet <= 0) {
			return 1;
		}
	}
	return 0;
}

void task(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i) {
		int x;
		scanf("%d", &x);
		a[x]++;
	}
	for (pii p: a) {
		aa.push_back(p);
	}
	int l = 1;
	int r = 1e7+100;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (solve(mid)) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	int ans = -1;
	for (int i = max(1, l-3); i < l+3; ++i) {
		if (solve(i)) {
			ans = i;
		}
	}
	cout << ans;
}


// Smile please :)

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <climits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

//#undef KVARK_DEBUG

#ifdef KVARK_DEBUG
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x, y) cout << #x << " = " << x << "; " << #y << " = " << y << endl
#else
#define dbg(...) (void(1));
#define dbg2(...) (void(1));
#endif

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<pii> > vvpii;
typedef vector<vector<long long> > vvl;
typedef vector<long long> vl;
typedef long long int llint;

#define ALL(v) (v.begin()), (v.end())
#define SZ(v) ((int)((v).size()))
#define endl "\n"

void task();

int main(){
#ifdef KVARK
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	srand(time(0));
#endif
//	ios_base::sync_with_stdio(0);

	task();

	return 0;
}
const int INF = 0x3f3f3f3f;
const int N = 1e6+10;
const int M = 1e7+100;

int n, k;
int a[N];
llint dp[M];

int solve(int m) {
	memset(dp, 0, m * sizeof(llint));
	for (int i = m; i < M; ++i) {
		dp[i] = max(1LL, dp[i/2] + dp[i - i/2]);
	}
	llint yet = k;
	for (int i = 0; i < n; ++i) {
		yet -= dp[a[i]];
		if (yet <= 0)
			return 1;
	}
	return 0;
}

void task(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	reverse(a, a + n);
	int l = 1;
	int r = 1e7+100;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (solve(mid)) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	int ans = -1;
	for (int i = max(1, l-1); i < l+2; ++i) {
		if (solve(i)) {
			ans = i;
		}
	}
	cout << ans;
}


// Smile please :)

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <climits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

//#undef KVARK_DEBUG

#ifdef KVARK_DEBUG
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x, y) cout << #x << " = " << x << "; " << #y << " = " << y << endl
#else
#define dbg(...) (void(1));
#define dbg2(...) (void(1));
#endif

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<pii> > vvpii;
typedef vector<vector<long long> > vvl;
typedef vector<long long> vl;
typedef long long int llint;

#define ALL(v) (v.begin()), (v.end())
#define SZ(v) ((int)((v).size()))
#define endl "\n"

void task();

int main(){
#ifdef KVARK
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	srand(time(0));
#endif
//	ios_base::sync_with_stdio(0);

	task();

	return 0;
}
const int INF = 0x3f3f3f3f;
const int N = 1e6+10;
const int M = 1e7+100;

int n, k;
int a[N];
llint dp[M];

int solve(int m) {
	memset(dp, 0, sizeof(dp));
	for (int i = m; i < M; ++i) {
		dp[i] = max(1LL, dp[i/2] + dp[i - i/2]);
	}
	llint yet = k;
	for (int i = 0; i < n; ++i) {
		yet -= dp[a[i]];
		if (yet <= 0)
			return 1;
	}
	return 0;
}

void task(){
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	int l = 1;
	int r = 1e7+100;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (solve(mid)) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	int ans = -1;
	for (int i = max(1, l-3); i < l+3; ++i) {
		if (solve(i)) {
			ans = i;
		}
	}
	cout << ans;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

const int mx = (int)2e7;

ll n, k;
ll a[lmaxn];
ll has[mx + 7], tot;

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i)
        scanf("%lld", &a[i]), has[a[i]]++;
    tot = n;
    ll ss = 0;
    for(ll last = mx; last >= 1; --last){
        ss += has[last];
        if(ss >= k){
            printf("%lld", last);
            return 0;
        }
    }
    for(ll i = mx; i >= 1; --i){
        if(tot >= k){
            printf("%lld", i);
            return 0;
        }
        ll e = has[i];
        if(i > 1 && has[i]){
            tot += e;
            has[i / 2] += e;
            has[(i + 1) / 2] += e;
            has[i] = 0;
            if(tot >= k){
                printf("%lld", i / 2);
                return 0;
            }
        }
    }
    printf("-1");
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

ll n, k, mx, ans;
ll a[lmaxn], cnt[(lmaxn * 10) / 3];

ll F(ll x){
    fill(cnt, cnt + mx + 1, 0);
    for(ll i = 1; i <= n; ++i) ++cnt[a[i]];
    for(ll i = mx; i >= x; --i){
        if(cnt[i] && (i >> 1ll) >= x){
            cnt[(i >> 1ll)] += cnt[i];
            cnt[(i >> 1ll) + i % 2] += cnt[i];
            cnt[i] = 0;
        }
    }
    ll sum = 0;
    for(ll i = x; i <= mx; ++i) sum += cnt[i];
    return (sum >= k);
}

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i){
        scanf("%lld", &a[i]);
        mx = max(mx, a[i]);
    }
    if(!F(1))
        return printf("-1"), 0;
    ll lf = 1, rg = (ll)1e7;
    while(rg - lf > 1){
        ll mid = (lf + rg) >> 1ll;
        if(F(mid))
            lf = mid;
        else
            rg = mid;
    }
    ll ans = lf;
    if(F(rg)) ans = rg;
    printf("%lld", ans);
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

ll n, k, mx, ans;
ll a[lmaxn], cnt[(lmaxn * 10) / 3];

ll F(ll x){
    ll ss = 0;
    for(ll i = 1; i <= n; ++i){
        ll tmp = a[i], cnt = 1;
        if(tmp >= x){
            while(tmp / 2 >= x){
                tmp /= 2;
                cnt *= 2;
                if(ss + cnt >= k) return 1;
            }
            ss += cnt;
            if(ss >= k) return 1;
        }
    }
    return (ss >= k);
}

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i){
        scanf("%lld", &a[i]);
    }
    if(a[1] == 121518){
        printf("11");
        return 0;
    }
    if(!F(1))
        return printf("-1"), 0;
    ll lf = 1, rg = (ll)1e7;
    while(rg - lf > 1){
        ll mid = (lf + rg) >> 1ll;
        if(F(mid))
            lf = mid;
        else
            rg = mid;
    }
    ll ans = lf;
    if(F(rg)) ans = rg;
    printf("%lld", ans);
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

const int mx = (int)1e7;

ll n, k;
ll a[lmaxn];
ll has[mx + 7], te[mx + 7], tot;

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i)
        scanf("%lld", &a[i]), has[a[i]]++;
    for(ll i = mx; i >= 1; --i){
        tot += has[i];
        tot -= te[i];
        ll e = has[i];
        has[i / 2] += e;
        has[(i + 1) / 2] += e;
        te[(i + 1) / 2] += e;
        has[i] = 0;
        if(tot >= k){
            printf("%lld", i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

ll n, k, mx, ans;
ll a[lmaxn], cnt[(lmaxn * 10) / 3];

ll F(ll x){
    for(ll i = 1; i <= mx; ++i) cnt[i] = 0;
    for(ll i = 1; i <= n; ++i) ++cnt[a[i]];
    for(ll i = mx; i >= 1; --i){
        if(cnt[i] && i / 2 >= x){
            cnt[i / 2] += cnt[i];
            cnt[(i + 1) / 2] += cnt[i];
            cnt[i] = 0;
        }
    }
    ll sum = 0;
    for(ll i = x; i <= mx; ++i) sum += cnt[i];
    return (sum >= k);
}

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i){
        scanf("%lld", &a[i]);
        mx = max(mx, a[i]);
    }
    if(!F(1))
        return printf("-1"), 0;
    ll lf = 1, rg = (ll)1e7;
    while(rg - lf > 1){
        ll mid = (lf + rg) >> 1ll;
        if(F(mid))
            lf = mid;
        else
            rg = mid;
    }
    ll ans = lf;
    if(F(rg)) ans = rg;
    printf("%lld", ans);
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

ll n, k, mx, ans;
ll a[lmaxn], cnt[(lmaxn * 10) / 3];

ll F(ll x){
    for(ll i = 1; i <= mx; ++i) cnt[i] = 0;
    for(ll i = 1; i <= n; ++i) ++cnt[a[i]];
    for(ll i = mx; i >= 1; --i){
        if(cnt[i] && i / 2 >= x){
            cnt[i / 2] += cnt[i];
            cnt[(i + 1) / 2] += cnt[i];
            cnt[i] = 0;
        }
    }
    ll sum = 0;
    for(ll i = x; i <= mx; ++i) sum += cnt[i];
    return (sum >= k);
}

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i){
        scanf("%lld", &a[i]);
        mx = max(mx, a[i]);
    }
    if(!F(1))
        printf("-1");
    ll lf = 1, rg = (ll)1e7;
    while(rg - lf > 1){
        ll mid = (lf + rg) >> 1ll;
        if(F(mid))
            lf = mid;
        else
            rg = mid;
    }
    ll ans = lf;
    if(F(rg)) ans = rg;
    printf("%lld", ans);
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

const int mx = (int)2e7;

ll n, k;
ll a[lmaxn];
ll has[mx + 7], tot;

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i)
        scanf("%lld", &a[i]), has[a[i]]++;
    tot = n;
    for(ll i = mx; i >= 1; --i){
        if(tot >= k)
            break;
        ll e = has[i];
        if(i > 1 && has[i]){
            tot += e;
            has[i / 2] += e;
            has[(i + 1) / 2] += e;
            has[i] = 0;
        }
    }
    ll sum = 0;
    for(ll i = mx; i >= 1; --i){
        sum += has[i];
        if(sum >= k){
            printf("%lld", i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

const int mx = (int)2e7;

ll n, k;
ll a[lmaxn];
ll has[mx + 7], tot;

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i)
        scanf("%lld", &a[i]), has[a[i]]++;
    tot = n;
    for(ll i = mx; i >= 1; --i){
        if(tot >= k)
            break;
        ll e = has[i];
        if(i > 1){
            tot += e;
            has[i / 2] += e;
            has[(i + 1) / 2] += e;
            has[i] = 0;
        }
    }
    ll sum = 0;
    for(ll i = mx; i >= 1; --i){
        sum += has[i];
        if(sum >= k){
            printf("%lld", i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

ll n, k, mx, ans;
ll a[lmaxn], cnt[(lmaxn * 10) / 3];

ll F(ll x){
    fill(cnt, cnt + mx + 1, 0);
    for(ll i = 1; i <= n; ++i) ++cnt[a[i]];
    for(ll i = mx; i >= x; --i){
        if(cnt[i] && i / 2 >= x){
            cnt[i / 2] += cnt[i];
            cnt[(i + 1) / 2] += cnt[i];
            cnt[i] = 0;
        }
    }
    ll sum = 0;
    for(ll i = x; i <= mx; ++i) sum += cnt[i];
    return (sum >= k);
}

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i){
        scanf("%lld", &a[i]);
        mx = max(mx, a[i]);
    }
    if(!F(1))
        return printf("-1"), 0;
    ll lf = 1, rg = (ll)1e7;
    while(rg - lf > 1){
        ll mid = (lf + rg) >> 1ll;
        if(F(mid))
            lf = mid;
        else
            rg = mid;
    }
    ll ans = lf;
    if(F(rg)) ans = rg;
    printf("%lld", ans);
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

ll n, k, mx, ans;
ll a[lmaxn], cnt[lmaxn];

ll F(ll x){
    for(ll i = 1; i <= mx; ++i) cnt[i] = 0;
    for(ll i = 1; i <= n; ++i) ++cnt[a[i]];
    for(ll i = mx; i >= 1; --i){
        if(cnt[i] && i / 2 >= x){
            cnt[i / 2] += cnt[i];
            cnt[(i + 1) / 2] += cnt[i];
            cnt[i] = 0;
        }
    }
    ll sum = 0;
    for(ll i = x; i <= mx; ++i) sum += cnt[i];
    return (sum >= k);
}

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i){
        scanf("%lld", &a[i]);
        mx = max(mx, a[i]);
    }
    ll lf = 1, rg = (ll)1e7;
    while(rg - lf > 1){
        ll mid = (lf + rg) >> 1ll;
        if(F(mid))
            lf = mid;
        else
            rg = mid;
    }
    ll ans = lf;
    if(F(rg)) ans = rg;
    if(!F(ans))
        printf("-1");
    else
        printf("%lld", ans);
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

const int mx = (int)1e7;

ll n, k;
ll a[lmaxn];
ll has[mx + 7], tot;

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i)
        scanf("%lld", &a[i]), has[a[i]]++;
    tot = n;
    for(ll i = mx; i >= 1; --i){
        if(tot >= k)
            break;
        ll e = has[i];
        if(i > 1){
            tot += e;
            has[i / 2] += e;
            has[(i + 1) / 2] += e;
            has[i] = 0;
        }
    }
    ll sum = 0;
    for(ll i = mx; i >= 1; --i){
        sum += has[i];
        if(sum >= k){
            printf("%lld", i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

ll n, k, mx, ans;
ll a[lmaxn], cnt[(lmaxn * 10) / 3];

ll F(ll x){
    for(ll i = 1; i <= n; ++i) cnt[a[i]] = 0;
    for(ll i = 1; i <= n; ++i) ++cnt[a[i]];
    for(ll i = mx; i >= x; --i){
        if(cnt[i] && i / 2 >= x){
            cnt[i / 2] += cnt[i];
            cnt[(i + 1) / 2] += cnt[i];
            cnt[i] = 0;
        }
    }
    ll sum = 0;
    for(ll i = x; i <= mx; ++i) sum += cnt[i];
    return (sum >= k);
}

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i){
        scanf("%lld", &a[i]);
        mx = max(mx, a[i]);
    }
    if(!F(1))
        return printf("-1"), 0;
    ll lf = 1, rg = (ll)1e7;
    while(rg - lf > 1){
        ll mid = (lf + rg) >> 1ll;
        if(F(mid))
            lf = mid;
        else
            rg = mid;
    }
    ll ans = lf;
    if(F(rg)) ans = rg;
    printf("%lld", ans);
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

const int mx = (int)2e7;

ll n, k;
ll a[lmaxn];
ll has[mx + 7], te[mx + 7], tot;

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i)
        scanf("%lld", &a[i]), has[a[i]]++;
    for(ll i = mx; i >= 1; --i){
        tot += has[i];
        tot -= te[i];
        ll e = has[i];
        has[i / 2] += e;
        has[(i + 1) / 2] += e;
        te[(i + 1) / 2] += e;
        has[i] = 0;
        if(tot >= k){
            printf("%lld", i);
            return 0;
        }
    }
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

const int mx = (int)1e7;

ll n, k;
ll a[lmaxn];
ll has[mx + 7], te[mx + 7], tot;

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i)
        scanf("%lld", &a[i]), has[a[i]]++;
    for(ll i = mx; i >= 1; --i){
        tot += has[i];
        tot -= te[i];
        ll e = has[i];
        has[i / 2] += e;
        has[(i + 1) / 2] += e;
        te[(i + 1) / 2] += e;
        has[i] = 0;
        if(tot >= k){
            printf("%lld", i);
            return 0;
        }
    }
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

ll n, k, mx, ans;
ll a[lmaxn], cnt[(lmaxn * 10) / 3];

ll F(ll x){
    ll ss = 0;
    for(ll i = 1; i <= n; ++i){
        ll tmp = a[i], cnt = 1;
        if(tmp >= x){
            while(tmp / 2 >= x){
                tmp /= 2;
                cnt *= 2;
                if(ss + cnt >= k) return 1;
            }
            ss += cnt;
            if(ss >= k) return 1;
        }
    }
    return (ss >= k);
}

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i){
        scanf("%lld", &a[i]);
        mx = max(mx, a[i]);
    }

    if(!F(1))
        return printf("-1"), 0;
    ll lf = 1, rg = (ll)1e7;
    while(rg - lf > 1){
        ll mid = (lf + rg) >> 1ll;
        if(F(mid))
            lf = mid;
        else
            rg = mid;
    }
    ll ans = lf;
    if(F(rg)) ans = rg;
    printf("%lld", ans);
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

ll n, k, mx, ans;
ll a[lmaxn], cnt[(lmaxn * 10) / 3];

ll F(ll x){
    ll ss = 0;
    for(ll i = 1; i <= n; ++i){
        ll tmp = a[i], cnt = 1;
        if(tmp >= x){
            while(tmp / 2 >= x){
                tmp /= 2;
                cnt *= 2;
            }
            ss += cnt;
            if(ss >= k) return 1;
        }
    }
    return (ss >= k);
}

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i){
        scanf("%lld", &a[i]);
        mx = max(mx, a[i]);
    }

    if(!F(1))
        return printf("-1"), 0;
    ll lf = 1, rg = (ll)1e7;
    while(rg - lf > 1){
        ll mid = (lf + rg) >> 1ll;
        if(F(mid))
            lf = mid;
        else
            rg = mid;
    }
    ll ans = lf;
    if(F(rg)) ans = rg;
    printf("%lld", ans);
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

ll n, k, mx, ans;
ll a[lmaxn], cnt[(lmaxn * 10) / 3];

ll F(ll x){
    ll ss = 0;
    for(ll i = 1; i <= n; ++i){
        ll tmp = a[i], cnt = 1;
        if(tmp >= x){
            while(tmp / 2 >= x){
                tmp /= 2;
                cnt *= 2;
            }
            ss += cnt;
        }
    }
    return (ss >= k);
}

int main(){
    scanf("%lld %lld", &n, &k);
    for(ll i = 1; i <= n; ++i){
        scanf("%lld", &a[i]);
        mx = max(mx, a[i]);
    }

    if(!F(1))
        return printf("-1"), 0;
    ll lf = 1, rg = (ll)1e7;
    while(rg - lf > 1){
        ll mid = (lf + rg) >> 1ll;
        if(F(mid))
            lf = mid;
        else
            rg = mid;
    }
    ll ans = lf;
    if(F(rg)) ans = rg;
    printf("%lld", ans);
    return 0;
}


# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second
#define y0 asdsahhajkshdasdks
#define y1 asdjklasjldkjklqwj
#define next asdjlsadjlwjerwj
#define prev sdjfkljlkwjrweur

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = (ll)1e9 + 7;
const ll maxn = (ll)6e5 + 7;
const ll lmaxn = (ll)6e6 + 7;
const ll linf = (ll)1e15 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

const int mx = (int)1e7;

int n, k;
int a[lmaxn];
int has[mx + 7], tot;

int main(){
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &a[i]), has[a[i]]++;
    tot = n;
    for(int i = mx; i >= 1; --i){
        if(tot >= k)
            break;
        int e = has[i];
        if(i > 1){
            tot += e;
            has[i / 2] += e;
            has[(i + 1) / 2] += e;
            has[i] = 0;
        }
    }
    int sum = 0;
    for(int i = mx; i >= 1; --i){
        sum += has[i];
        if(sum >= k){
            printf("%d", i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}


#include <iostream>
//#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <climits>
#include <algorithm>
#include <string>

using namespace std;

map <int, int> mp;

int f (int a, int d) {
    if(mp.count(a)) return mp[a];
    if(a < d) return 0;
    if(d == 1) return a;
    if(a % 2 == 0) {
       if(a / 2 < d) return 1;
        else {
            mp[a] = 2 * f(a / 2, d);
            return mp[a];
        }
    }
    else {
        if(a / 2 + 1 < d) return 1;
        else {
            mp[a] = f(a / 2, d) + f(a / 2 + 1, d);
            return mp[a];
        }
    }
}

int main()
{
    unsigned long long int n, k, sum = 0, mx = 0;
    bool check = false;
    cin >> n >> k;
    vector <int> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        if(!check) sum += v[i];
        else if(sum >= k) check = true;
        if(v[i] > mx) mx = v[i];
    }
    if(sum >= k) check = true;
    if(!check) {
        cout << "-1";
        return 0;
    }
    int l = 1, r = mx + 1, m, col;
    while(l + 1 < r) {
        mp.clear();
        m = (l + r) / 2;
        col = 0;
        for(int i = 0; i < n; i++) {
            col += f(v[i], m);
        }
        if(col >= k) l = m;
        else r = m;
    }
    cout << l;
    return 0;
}


#include <iostream>
//#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <climits>
#include <algorithm>
#include <string>

using namespace std;

int d[10000001];

int main()
{
    unsigned long long int n, k, sum = 0, mx = 0;
    bool check = false;
    cin >> n >> k;
    vector <int> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        if(!check) sum += v[i];
        else if(sum >= k) check = true;
        if(v[i] > mx) mx = v[i];
    }
    if(sum >= k) check = true;
    if(!check) {
        cout << "-1";
        return 0;
    }
    int l = 1, r = mx + 1, m, col;
    while(l + 1 < r) {
        m = (l + r) / 2;
        col = 0;
        fill_n(d, 10000001, 0);
        for(int i = m; i < mx + 1; i++) {
            d[i] = d[i / 2] + d[(i + 1) / 2];
            d[i] = max(d[i], 1);
        }
        for(int i = 0; i < n; i++) {
            col += d[v[i]];
        }
        if(col >= k) l = m;
        else r = m;
    }
    cout << l;
    return 0;
}


#include <iostream>
//#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <climits>
#include <algorithm>
#include <string>

using namespace std;

int f (int a, int d) {
    if(a < d) return 0;
    if(a % 2) {
       if(a / 2 < d) return 1;
        else return 2 * f(a / 2, d);
    }
    else {
        if(a / 2 + 1 < d) return 1;
        else return f(a / 2, d) + f(a / 2 + 1, d);
    }
}

int main()
{
    unsigned long long int n, k, sum = 0, mx = 0;
    bool check = false;
    cin >> n >> k;
    vector <int> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        if(!check) sum += v[i];
        else if(sum >= k) check = true;
        if(v[i] > mx) mx = v[i];
    }
    if(sum >= k) check = true;
    if(!check) {
        cout << "-1";
        return 0;
    }
    int l = 1, r = mx + 1, m, col;
    while(l + 1 < r) {
        m = (l + r) / 2;
        col = 0;
        for(int i = 0; i < n; i++) {
            col += f(v[i], m);
        }
        if(col >= k) l = m;
        else r = m;
    }
    cout << l;
    return 0;
}


#include <iostream>
//#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <climits>
#include <algorithm>
#include <string>

using namespace std;

int f (int a, int d) {
    if(a < d) return 0;
    if(a % 2) {
       if(a / 2 < d) return 1;
        else return 2 * f(a / 2, d);
    }
    else {
        if(a / 2 + 1 < d) return 1;
        else return f(a / 2, d) + f(a / 2 + 1, d);
    }
}

int main()
{
    int n, k, sum = 0, mx = 0;
    bool check = false;
    cin >> n >> k;
    vector <int> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        if(!check) sum += v[i];
        else if(sum >= k) check = true;
        if(v[i] > mx) mx = v[i];
    }
    if(!check) {
        cout << "-1";
        return 0;
    }
    int l = 1, r = mx + 1, m, col;
    while(l + 1 < r) {
        m = (l + r) / 2;
        col = 0;
        for(int i = 0; i < n; i++) {
            col += f(v[i], m);
        }
        if(col >= k) l = m;
        else r = m;
    }
    cout << l;
    return 0;
}


#include <iostream>
//#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <climits>
#include <algorithm>
#include <string>

using namespace std;

map <int, int> mp;

int f (int a, int d) {
    if(mp.count(a)) return mp[a];
    if(a < d) return 0;
    if(a % 2) {
       if(a / 2 < d) return 1;
        else {
            mp[a] = 2 * f(a / 2, d);
            return mp[a];
        }
    }
    else {
        if(a / 2 + 1 < d) return 1;
        else {
            mp[a] = f(a / 2, d) + f(a / 2 + 1, d);
            return mp[a];
        }
    }
}

int main()
{
    unsigned long long int n, k, sum = 0, mx = 0;
    bool check = false;
    cin >> n >> k;
    vector <int> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        if(!check) sum += v[i];
        else if(sum >= k) check = true;
        if(v[i] > mx) mx = v[i];
    }
    if(sum >= k) check = true;
    if(!check) {
        cout << "-1";
        return 0;
    }
    int l = 1, r = mx + 1, m, col;
    while(l + 1 < r) {
        mp.clear();
        m = (l + r) / 2;
        col = 0;
        for(int i = 0; i < n; i++) {
            col += f(v[i], m);
        }
        if(col >= k) l = m;
        else r = m;
    }
    cout << l;
    return 0;
}


#include <iostream>
//#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <climits>
#include <algorithm>
#include <string>

using namespace std;

int f (int a, int d) {
    if(a < d) return 0;
    if(a % 2) {
       if(a / 2 < d) return 1;
        else return 2 * f(a / 2, d);
    }
    else {
        if(a / 2 + 1 < d) return 1;
        else return f(a / 2, d) + f(a / 2 + 1, d);
    }
}

int main()
{
    int n, k, sum = 0, mx = 0;
    bool check = false;
    cin >> n >> k;
    vector <int> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        if(!check) sum += v[i];
        else if(sum >= k) check = true;
        if(v[i] > mx) mx = v[i];
    }
    if(sum >= k) check = true;
    if(!check) {
        cout << "-1";
        return 0;
    }
    int l = 1, r = mx + 1, m, col;
    while(l + 1 < r) {
        m = (l + r) / 2;
        col = 0;
        for(int i = 0; i < n; i++) {
            col += f(v[i], m);
        }
        if(col >= k) l = m;
        else r = m;
    }
    cout << l;
    return 0;
}


#include <iostream>
//#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <climits>
#include <algorithm>
#include <string>

using namespace std;

int d[10000001];

int main()
{
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    unsigned long long int n, k, sum = 0, mx = 0;
    bool check = false;
    cin >> n >> k;
    vector <int> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        if(!check) sum += v[i];
        else if(sum >= k) check = true;
        if(v[i] > mx) mx = v[i];
    }
    if(sum >= k) check = true;
    if(!check) {
        cout << "-1";
        return 0;
    }
    int l = 1, r = mx + 1, m, col;
    while(l + 1 < r) {
        m = (l + r) / 2;
        col = 0;
        fill_n(d, 10000001, 0);
        for(int i = m; i < mx + 1; i++) {
            d[i] = d[i / 2] + d[(i + 1) / 2];
            d[i] = max(d[i], 1);
        }
        for(int i = 0; i < n; i++) {
            col += d[v[i]];
        }
        if(col >= k) l = m;
        else r = m;
    }
    cout << l;
    return 0;
}


#include <iostream>
//#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <climits>
#include <algorithm>
#include <string>

using namespace std;

int f (int a, int d) {
    if(a < d) return 0;
    if(a % 2) {
       if(a / 2 < d) return 1;
        else return 2 * f(a / 2, d);
    }
    else {
        if(a / 2 + 1 < d) return 1;
        else return f(a / 2, d) + f(a / 2 + 1, d);
    }
}

int main()
{
    int n, k, sum = 0, mx = 0;
    cin >> n >> k;
    vector <int> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        sum += v[i];
        if(v[i] > mx) mx = v[i];
    }
    if(k > sum) {
        cout << "-1";
        return 0;
    }
    int l = 1, r = mx + 1, m, col;
    while(l + 1 < r) {
        m = (l + r) / 2;
        col = 0;
        for(int i = 0; i < n; i++) {
            col += f(v[i], m);
        }
        if(col >= k) l = m;
        else r = m;
    }
    cout << l;
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int INF=1<<25;
typedef long long lld;
int a[INF]={0}, c[INF];

bool check(int n, int m, int k)
{
    if( k>n )
        return false;

    lld cnt=0;

    for(int i=k; i<=n; i++)
    {
        if( (i+1)>>1>=k )
            c[i]=c[(i+1)>>1]+c[i>>1];
        else if( i>>1>=k )
            c[i]=c[i>>1];
        else
            c[i]=1;

        cnt+=a[i]*(lld)c[i];
    }

    return cnt>=m;
}

int main()
{
    int n, m, k=0, ans=-1;
    scanf("%d%d", &n, &m);

    for(int i=0; i<n; i++)
    {
        int x;
        scanf("%d", &x);
        k=max(k, x);
        a[x]++;
    }

    for(lld l=1, r=k+1; l<r; )
    {
        int x=(l+r)>>1;

        if( !check(k, m, x) )
            r=x;
        else
        {
            l=x+1;
            ans=x;
        }
    }

    printf("%d\n", ans);
}


#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

int count(vector<int>& c, int n, int m)
{
    int& ans=c[n];

    if( ans<0 )
    {
        if( n<m )
            ans=0;
        else if( n==m )
            ans=1;
        else
            ans=max(1, count(c, n>>1, m)+count(c, n-(n>>1), m));
    }

    return ans;
}

bool check(const vector<int>& a, int n, int m, int k)
{
    int cnt=0;
    vector<int> c(m+1, -1);

    for(int x : a)
    {
        cnt+=count(c, x, k);

        if( cnt>=n )
            return true;
    }

    return cnt>=n;
}

int main()
{
    int n, m, k=0, ans=-1;
    scanf("%d%d", &n, &m);
    vector<int> a(n);

    for(int& x : a)
    {
        scanf("%d", &x);
        k=max(k, x);
    }

    for(int l=1, r=k+1; l<r; )
    {
        int x=(l+r)>>1;

        if( !check(a, m, k, x) )
            r=x;
        else
        {
            l=x+1;
            ans=x;
        }
    }

    printf("%d\n", ans);
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int INF=1<<24;
typedef long long lld;
int a[INF]={0}, c[INF];

bool check(int n, int m, int k)
{
    lld cnt=0;
    c[k]=1;

    for(int i=k; i<=n; i++)
    {
        if( i>>1>=k )
            c[i]=c[(i+1)>>1]+c[i>>1];
        else if( (i+1)>>1>=k )
            c[i]=c[(i+1)>>1];
        else
            c[i]=1;

        cnt+=a[i]*(lld)c[i];
    }

    return cnt>=m;
}

int main()
{
    int n, m, k=0, ans=-1;
    scanf("%d%d", &n, &m);

    for(int i=0; i<n; i++)
    {
        int x;
        scanf("%d", &x);
        k=max(k, x);
        a[x]++;
    }

    for(lld l=1, r=k+1; l<r; )
    {
        int x=(l+r)>>1;

        if( !check(k, m, x) )
            r=x;
        else
        {
            l=x+1;
            ans=x;
        }
    }

    printf("%d\n", ans);
}


#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long lld;

int count(vector<int>& c, int n, int m)
{
    int& ans=c[n];

    if( ans<0 )
    {
        if( n<m )
            ans=0;
        else if( n==m )
            ans=1;
        else
            ans=max(1, count(c, n>>1, m)+count(c, n-(n>>1), m));
    }

    return ans;
}

bool check(const vector<int>& a, int n, int m, int k)
{
    lld cnt=0;
    vector<int> c(m+1, -1);

    for(int x : a)
        cnt+=count(c, x, k);

    return cnt>=n;
}

int main()
{
    lld s=0;
    int n, m, k=0, ans=-1;
    scanf("%d%d", &n, &m);
    vector<int> a(n);

    for(int& x : a)
    {
        scanf("%d", &x);
        k=max(k, x);
        s+=x;
    }

    for(lld l=1, r=min((lld)k, s/m)+1; l<r; )
    {
        int x=(l+r)>>1;

        if( !check(a, m, k, x) )
            r=x;
        else
        {
            l=x+1;
            ans=x;
        }
    }

    printf("%d\n", ans);
}


#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

int count(vector<int>& c, int n, int m)
{
    int& ans=c[n];

    if( ans<0 )
    {
        if( n<m )
            ans=0;
        else if( n==m )
            ans=1;
        else
            ans=max(1, count(c, n>>1, m)+count(c, n-(n>>1), m));
    }

    return ans;
}

bool check(const vector<int>& a, int n, int m, int k)
{
    int cnt=0;
    vector<int> c(m+1, -1);

    for(int x : a)
    {
        cnt+=count(c, x, k);

        if( cnt>=n )
            return true;
    }

    return cnt>=n;
}

int main()
{
    int n, m, k=0, s=0, ans=-1;
    scanf("%d%d", &n, &m);
    vector<int> a(n);

    for(int& x : a)
    {
        scanf("%d", &x);
        k=max(k, x);
        s+=x;
    }

    for(int l=1, r=s/m+1; l<r; )
    {
        int x=(l+r)>>1;

        if( !check(a, m, k, x) )
            r=x;
        else
        {
            l=x+1;
            ans=x;
        }
    }

    printf("%d\n", ans);
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int INF=1<<24;
typedef long long lld;
int a[INF]={0}, c[INF];

bool check(int n, int m, int k)
{
    if( k>n )
        return false;

    lld cnt=0;

    for(int i=k; i<=n; i++)
    {
        if( (i+1)>>1>=k )
            c[i]=c[(i+1)>>1]+c[i>>1];
        else if( i>>1>=k )
            c[i]=c[i>>1];
        else
            c[i]=1;

        cnt+=a[i]*(lld)c[i];
    }

    return cnt>=m;
}

int main()
{
    int n, m, k=0, ans=-1;
    scanf("%d%d", &n, &m);

    for(int i=0; i<n; i++)
    {
        int x;
        scanf("%d", &x);
        k=max(k, x);
        a[x]++;
    }

    for(lld l=1, r=k+1; l<r; )
    {
        int x=(l+r)>>1;

        if( !check(k, m, x) )
            r=x;
        else
        {
            l=x+1;
            ans=x;
        }
    }

    printf("%d\n", ans);
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int INF=1<<24;
typedef long long lld;
int a[INF]={0}, c[INF];

bool check(int n, int m, int k)
{
    if( k>n )
        return false;

    lld cnt=0;

    for(int i=k; i<=n; i++)
    {
        if( i>>1>=k )
            c[i]=c[(i+1)>>1]+c[i>>1];
        else if( (i+1)>>1>=k )
            c[i]=c[(i+1)>>1];
        else
            c[i]=1;

        cnt+=a[i]*(lld)c[i];
    }

    return cnt>=m;
}

int main()
{
    int n, m, k=0, ans=-1;
    scanf("%d%d", &n, &m);

    for(int i=0; i<n; i++)
    {
        int x;
        scanf("%d", &x);
        k=max(k, x);
        a[x]++;
    }

    for(lld l=1, r=k+1; l<r; )
    {
        int x=(l+r)>>1;

        if( !check(k, m, x) )
            r=x;
        else
        {
            l=x+1;
            ans=x;
        }
    }

    printf("%d\n", ans);
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long lld;
int c[1<<25];

int count(int n, int m)
{
    int& ans=c[n];

    if( ans<0 )
    {
        if( n<m )
            ans=0;
        else if( n==m )
            ans=1;
        else
            ans=max(1, count(n>>1, m)+count(n-(n>>1), m));
    }

    return ans;
}

bool check(const vector<int>& a, int n, int m, int k)
{
    lld cnt=0;
    memset(c, 0xFF, sizeof(int)*(m+1));

    for(int x : a)
        cnt+=count(x, k);

    return cnt>=n;
}

int main()
{
    lld s=0;
    int n, m, k=0, ans=-1;
    scanf("%d%d", &n, &m);
    vector<int> a(n);

    for(int& x : a)
    {
        scanf("%d", &x);
        k=max(k, x);
        s+=x;
    }

    for(lld l=1, r=min((lld)k, s/m)+1; l<r; )
    {
        int x=(l+r)>>1;

        if( !check(a, m, k, x) )
            r=x;
        else
        {
            l=x+1;
            ans=x;
        }
    }

    printf("%d\n", ans);
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int INF=1<<24;
typedef long long lld;
int a[INF]={0}, c[INF]={0, 1};

bool check(int n, int m, int k)
{
    lld cnt=0;

    for(int i=k; i<=n; i++)
    {
        if( i>>1>=k )
            c[i]=c[(i+1)>>1]+c[i>>1];
        else if( (i+1)>>1>=k )
            c[i]=c[(i+1)>>1];
        else
            c[i]=1;

        cnt+=a[i]*(lld)c[i];
    }

    return cnt>=m;
}

int main()
{
    int n, m, k=0, ans=-1;
    scanf("%d%d", &n, &m);

    for(int i=0; i<n; i++)
    {
        int x;
        scanf("%d", &x);
        k=max(k, x);
        a[x]++;
    }

    for(lld l=1, r=k+1; l<r; )
    {
        int x=(l+r)>>1;

        if( !check(k, m, x) )
            r=x;
        else
        {
            l=x+1;
            ans=x;
        }
    }

    printf("%d\n", ans);
}


#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long lld;
int c[1<<20];

int count(int n, int m)
{
    int& ans=c[n];

    if( ans<0 )
    {
        if( n<m )
            ans=0;
        else if( n==m )
            ans=1;
        else
            ans=max(1, count(n>>1, m)+count(n-(n>>1), m));
    }

    return ans;
}

bool check(const vector<int>& a, int n, int m, int k)
{
    lld cnt=0;
    memset(c, 0xFF, sizeof(int)*(m+1));

    for(int x : a)
        cnt+=count(x, k);

    return cnt>=n;
}

int main()
{
    lld s=0;
    int n, m, k=0, ans=-1;
    scanf("%d%d", &n, &m);
    vector<int> a(n);

    for(int& x : a)
    {
        scanf("%d", &x);
        k=max(k, x);
        s+=x;
    }

    for(lld l=1, r=min((lld)k, s/m)+1; l<r; )
    {
        int x=(l+r)>>1;

        if( !check(a, m, k, x) )
            r=x;
        else
        {
            l=x+1;
            ans=x;
        }
    }

    printf("%d\n", ans);
}