#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = (LL)998244353;
const int SIZE = 1<<19;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

int a[200009];
LL fw[2][SIZE];

LL qu(int i, int x){
    LL ans = 0;
    for(;x;x-=x&(-x))ans+=fw[i][x];
    return ans;
}

void up(int i, int x,int v){
    for(;x<SIZE;x+=x&(-x))fw[i][x]+=v;
}

void upr(int a, int b, LL v){
    a++;b++;
    up(1,a,v);
    up(1,b+1,-v);
    up(0,a,-v*(a-1));
    up(0,b+1,v*b);
}

LL qur(int x){
    x++;
    return qu(1,x)*x+qu(0,x);
}

int bs(LL v){
    int x = 0;
    LL m=0, c=0;
    for(int bi = 18;bi>=0;bi--){//largest position with value < v
        int nx = x + (1<<bi);
        LL nm = m + fw[1][nx];
        LL nc = c + fw[0][nx];
        if(nm*nx+nc < v){
            x = nx;
            m = nm;
            c = nc;
        }
    }
    return x;
}

int main(){
    DRII(n,k);
    REP(i,n){
        RI(a[i]);
    }
    upr(0,0,1);//height of 0 has 1!
    int mh = 0;
    int ans = 1e9;
    sort(a,a+n,greater<int>());
    REP(i,n){
        while(qur(mh)==0)mh++;
        upr(mh,mh,-1);
        int l = (a[i]-1)/2; 
        int r = a[i]-1 - l;
        //printf("%d %d %d\n",mh,l,r);
        upr(mh+2, mh+l+1, 1);
        upr(mh+2, mh+r+1, 1);
        int bsr = bs(k);
        if(bs(k)!=SIZE-1)ans = min(ans, bsr);
        //REP(j,10)printf("%lld ",qur(j));
        //puts("");
    }
    if(ans<1e9)printf("%d", ans);
    else puts("-1");
}
