#include <bits/stdc++.h>
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef ARTHUR_LOCAL
	#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
	const int MXN=100;
#else
	#define debug(x...)
	const int MXN=300000;
#endif

using ll = long long;
 
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define len(x) int((x).size())

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(n) uniform_int_distribution<int>(1, (n))(rng)

int mini[MXN];
vector<int> tailed[MXN];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	int n,k;
	cin>>n>>k;
	vector<int> L(n);
	vector<int> cnt(MXN);
	for(int i=0; i<n; i++){
		int l;
		cin>>l;
		cnt[l]++;
	}

	int lindex=0;

	for(int i=0; i<MXN; i++){
		while(cnt[i]--) L[lindex++]=i;
	}

	mini[0]=1;

	for(int d=0; d<MXN; d++){

		debug(d);
		debug(mini[d]);
		debug(len(tailed[d]));
		debug(mini[d+1]);
		// debug

		if(mini[d] + len(tailed[d]) >= k){
			cout<<d<<"\n";
			return 0;
		}

		if(mini[d] + 2*len(tailed[d]) + len(tailed[d+1]) + mini[d+1] >= k){
			cout<<d+1<<"\n";
			return 0;
		}

		while(!L.empty() && (mini[d]>0 || !tailed[d].empty())){
			int curl = L.back();
			L.pop_back();

			int curtail; 
			
			if(!tailed[d].empty()){
				curtail=tailed[d].back();
				tailed[d].pop_back();
			}

			else{
				curtail=1;
				mini[d]--;
			}

			if(curtail>2) tailed[d+1].push_back(curtail-1);
			if(curtail==2) mini[d+1]++;

			int l1 = int(curl/2);
			int l2 = int(curl/2) - int(curl%2==0);

			// cout<<l1<<" "<<l2<<endl;
			debug(l1);
			debug(l2);
			
			if(l1!=1) tailed[d+2].push_back(l1);
			else mini[d+2]++;

			if(l2!=1) tailed[d+2].push_back(l2);
			else mini[d+2]++;
		}
		// while(!L.empty()

		if(L.empty()){
		
			debug(mini[3]);

			int cur=len(tailed[d]) + mini[d];
			vector<int> last_laugh(MXN);
			// priority_queue<int> last_laugh;
			int carry=0;
			while(!tailed[d].empty()){
				last_laugh[tailed[d].back()+d-1]++;
				carry++;
				tailed[d].pop_back();
			}

			debug(carry);

			for(int e=d+1; e<MXN; e++){
				
				debug(e);

				cur+=len(tailed[e]) + mini[e];
				cur+=carry;

				debug(cur);

				while(last_laugh[e]>0){ // while(!last_laugh.empty()&&-last_laugh.top()==e){
					carry--;
					last_laugh[e]--;
				}

				while(!tailed[e].empty()){
					last_laugh[tailed[e].back()+e-1]++; // .push(-(tailed[e].back()+e-1));
					carry++;
					tailed[e].pop_back();
				}

				if(cur >= k){
					cout<<e<<"\n";
					return 0;
				}
			}

			cout<<-1<<"\n";
			return 0;
		}
	}
}