#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define N 500010
#define NN 1000100
#define PB push_back
#define PF push_front
#define sz(x) int(x.size())
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define _ << " " <<
#define endl '\n'
#define M ll(998244353)
#define pri(x) cout << x << endl

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef array <int, 3> a3;
//typedef tree <int, null_type, less_equal <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int n, k;

int a[N], t[N * 4], psh[N * 4], skok[N];

void comp(int v)
{
    if (t[v + v] == -1) t[v] = t[v + v + 1];
     else t[v] = t[v + v];
}

void Push(int v, int tl, int tr)
{
    if (psh[v] == 0) return;

    t[v] = tl;

    if (tl == tr)
    {
        t[v] = tl;

        skok[tl] += psh[v];
    }
      else
      {
          int md = (tl + tr) >> 1;

          t[v + v] = tl;

          psh[v + v] += psh[v];

          t[v + v + 1] = md + 1;

          psh[v + v + 1] += psh[v];
      }

    psh[v] = 0;
}

void updr(int v, int tl, int tr, int ps)
{
    Push(v, tl, tr);

    if (tl == tr)
    {
        skok[tl]--;

        if (skok[tl] == 0) t[v] = -1;

        return;
    }

    int md = (tl + tr) >> 1;

    if (ps <= md)
        updr(v + v, tl, md, ps);
           else updr(v + v + 1, md + 1, tr, ps);

    comp(v);
}

void upd(int v, int tl, int tr, int l, int r)
{
    Push(v, tl, tr);

    if (tr < l || r < tl || l > r || tl > tr) return;

    if (l <= tl && tr <= r) {psh[v]++; Push(v, tl, tr); return;}

    int md = (tl + tr) >> 1;

    upd(v + v, tl, md, l, r);

    upd(v + v + 1, md + 1, tr, l, r);

    comp(v);
}

bool can(int x)
{
    for (int i = 0; i < N * 4; i++) {t[i] = -1; psh[i] = 0;}

    for (int i = 0; i < N; i++) skok[i] = 0;

    upd(1, 0, N - 1, 0, 0);

    int num = 1, j = 0;

    while (j < n && num < k && num > 0)
    {
        int val = a[j];

        int ps = t[1];

        updr(1, 0, N - 1, ps);

        int L = val / 2, R = (val - 1) / 2;

        num += min(L, x - ps - 1) + min(R, x - ps - 1);

        num--;

        upd(1, 0, N - 1, ps + 2, min(x, ps + L + 1));

        upd(1, 0, N - 1, ps + 2, min(x, ps + R + 1));

        j++;
    }

    return num >= k;
}

int main()
{
	iostream::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("queries.in", "r", stdin); freopen("queries.out", "w", stdout);

    cin >> n >> k;

    ll sum = 0;

    for (int i = 0; i < n; i++) {cin >> a[i]; sum += a[i];}

    sum -= n + n - 1;

    if (k > sum) {pri(-1); exit(0);}

    sort(a, a + n);

    reverse(a, a + n);

    int l = 0, r = N - 1;

    while (l < r)
    {
        int md = (l + r) >> 1;

        if (can(md)) r = md;
          else l = md + 1;
    }

    pri(l);
}
