#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; int N, M; bool C(int x, int mid, vector& v){ int m = x + mid; int ret = 0; vector w; REP(i,1,v.size()){ if(i==mid) continue; w.push_back(v[i]); } sort(ALLOF(w)); for(int i=w.size()-1; i>=0; i-=2){ if(w[i]+w[i-1] > m) ret++; } return ret < M; } int main(){ cin >> N >> M; vector v; int x; cin >> x; rep(i,N-1){ int a; cin >> a; v.push_back(a); } if(N==2){ cout << v[0] << endl; return 0; } sort(ALLOF(v)); int ret = 1000000005; int lb = 0, ub = v.size(); while(ub-lb>1){ int mid = (lb+ub)/2; //cout << " " << mid << " " << C(x,mid,v) << endl; bool flg = C(x, mid, v); if(flg){ ret = min(ret, v[mid]); } if(flg) ub = mid; else lb = mid; } if(ret == 1000000005) cout << -1 << endl; else cout << ret << endl; return 0; }