#include using namespace std; #define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++) #define ALL(x) x.begin(),x.end() template bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; } template bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; } typedef long long ll; int N,M,K; vector A; int f(int m) { multiset st; FOR(i,0,N) if(i != m){ st.insert(A [i]); } int res = 0; while(st.empty() == false){ int x = *(--st.end()); st.erase(--st.end()); auto it = st.upper_bound(K + A [m] - x); if(it == st.end()) break; st.erase(it); res++; } return res; } int main() { scanf("%d%d",&N,&M); N--; scanf("%d",&K); A.assign(N,0); FOR(i,0,N){ scanf("%d",&A [i]); } sort(ALL(A)); if(f(N - 1) >= M){ puts("-1"); return 0; } int ok = N - 1,ng = -1,mid; while(ok - ng > 1){ mid = (ok + ng) / 2; if(f(mid) < M){ ok = mid; } else{ ng = mid; } } printf("%d\n",A [ok]); return 0; }