#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// source: Me, based off github/the-tourist/algo
class segtree {
public:
    struct node {
        ll val;
        ll lazyVal;
        bool identity;
        node() {
            val = lazyVal = 0;
            identity = false;
        }

        void apply(int l, int r, ll v) {
            //make sure to update lazyVal here
            val += (r - l + 1) * v;
            lazyVal += v;
        }
    };
    
    node unite(const node &a, const node &b) const {
        // combines two nodes
        if(a.identity) return b;
        if(b.identity) return a;
        node res;
        res.val = a.val + b.val;
        return res;
    }

    inline void push(int x, int l, int r) {
        // return; if no lazy prop
        // make sure to reset lazyValue here, lazy is added in apply function
        int mid = (l + r) >> 1;
        if (l != r) {
            tree[2 * x].apply(l, mid, tree[x].lazyVal);
            tree[2 * x + 1].apply(mid + 1, r, tree[x].lazyVal);
        }
        tree[x].lazyVal = 0;
    }

    inline void pull(int x) { tree[x] = unite(tree[2 * x], tree[2 * x + 1]); }

    int n;
    vector<node> tree;
    segtree(int _n) : n(_n) {
        assert(n > 0);
        tree.resize(4 * n);
        build(1, 0, n - 1);
    }
    template <typename M>
    segtree(const vector<M> &v) {
        n = v.size();
        assert(n > 0);
        tree.resize(4 * n);
        build(1, 0, n - 1, v);
    }
    node get(int ll, int rr) {
        assert(0 <= ll && ll <= rr && rr <= n - 1);
        return get(1, 0, n - 1, ll, rr);
    }
    int bS(int v){
        return bS(1, 0, n - 1, v);
    }
    template <typename... M>
    void modify(int ll, int rr, const M &... v) {
        assert(0 <= ll && ll <= rr && rr <= n - 1);
        modify(1, 0, n - 1, ll, rr, v...);
    }

private:
    void build(int x, int l, int r) {
        if (l == r) {
            return;
        }
        int mid = (l + r) >> 1;
        build(2 * x, l, mid);
        build(2 * x + 1, mid + 1, r);
        pull(x);
    }
    template <typename M>
    void build(int x, int l, int r, const vector<M> &v) {
        if (l == r) {
            tree[x].apply(l, r, v[l]);
            return;
        }
        int mid = (l + r) >> 1;
        build(2 * x, l, mid, v);
        build(2 * x + 1, mid + 1, r, v);
        pull(x);
    }
    int bS(int x, int l, int r, int v) {
        if(tree[x].val < v) return -1;
        if(l==r) return l;
        int mid = (l + r) >> 1;
        push(x, l, r); 
        int res;
        if(v <= tree[2*x].val) res = bS(2*x, l, mid, v);
        else res = bS(2*x+1, mid+1, r, v-tree[2*x].val);
        pull(x);
        return res;
    }
    node get(int x, int l, int r, int ll, int rr) {
        node res{};
        res.identity = true;
        if (ll > r || l > rr) return res;
        if (ll <= l && r <= rr) return tree[x];
        int mid = (l + r) >> 1;
        push(x, l, r);
        res = unite(get(2 * x, l, mid, ll, rr),
                    get(2 * x + 1, mid + 1, r, ll, rr));
        pull(x);
        return res;
    }
    template <typename... M>
    void modify(int x, int l, int r, int ll, int rr, const M &... v) {
        if (ll > r || l > rr) return;
        if (ll <= l && r <= rr) {
            tree[x].apply(l, r, v...);
            return;
        }
        int mid = (l + r) >> 1;
        push(x, l, r);
        modify(2 * x, l, mid, ll, rr, v...);
        modify(2 * x + 1, mid + 1, r, ll, rr, v...);
        pull(x);
    }
};
const int MAXN = 2e5;
void run_case(){
    int n, k;
    cin>>n>>k;
    vector<int> l(n); 
    ll sum = 1;
    for(int& i:l) {
        cin>>i;
        sum += i;
    }
    sum -= 2 * n;
    if(sum<k){
        cout<<"-1\n";
        return;
    }
    
    sort(l.begin(), l.end(), greater<int>());
    segtree st(2*MAXN);
    st.modify(0, 0, 1);
    int ans = -1;
    int ind = 0;
    for(int i = 0; i< n; i++){
        while(st.get(ind, ind).val==0) ind++;
        st.modify(ind, ind, -1);
        int len = l[i]/2;
        st.modify(ind+2, ind+2+len-1, 1);
        st.modify(ind+2, ind+2+(l[i]-1-len)-1, 1);
        // cout<<ind<<" "<<len<<" "<<ind+2+(l[i]-1-len)<<endl;
        // cout<<st.get(2,2).val<<endl;
        // cout<<st.get(3,3).val<<endl;
        int cur = st.bS(k);
        if(cur!=-1) {
            // cout<<i<<" "<<cur<<endl;
            if(ans==-1 || cur < ans)
                ans = cur;
        }
    }
    cout<<ans<<'\n';

}
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    if (fopen("input.in", "r")) 
        freopen("input.in", "r", stdin), freopen("output.out", "w", stdout);
    int t;
    t=1;
    while(t--){
        run_case();
    }
}

### Prompt

Construct a Cpp code solution to the problem outlined:

// We decided to drop the legend about the power sockets but feel free to come up with your own :^)

Define a chain: 

  * a chain of length 1 is a single vertex; 
  * a chain of length x is a chain of length x-1 with a new vertex connected to the end of it with a single edge. 



You are given n chains of lengths l_1, l_2, ..., l_n. You plan to build a tree using some of them.

  * Each vertex of the tree is either white or black. 
  * The tree initially only has a white root vertex. 
  * All chains initially consist only of white vertices. 
  * You can take one of the chains and connect any of its vertices to any white vertex of the tree with an edge. The chain becomes part of the tree. Both endpoints of this edge become black. 
  * Each chain can be used no more than once. 
  * Some chains can be left unused. 



The distance between two vertices of the tree is the number of edges on the shortest path between them.

If there is at least k white vertices in the resulting tree, then the value of the tree is the distance between the root and the k-th closest white vertex.

What's the minimum value of the tree you can obtain? If there is no way to build a tree with at least k white vertices, then print -1.

Input

The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9) — the number of chains and the minimum number of white vertices a tree should have to have a value.

The second line contains n integers l_1, l_2, ..., l_n (3 ≤ l_i ≤ 2 ⋅ 10^5) — the lengths of the chains.

Output

Print a single integer. If there is no way to build a tree with at least k white vertices, then print -1. Otherwise, print the minimum value the tree can have.

Examples

Input


1 2
3


Output


2


Input


3 3
4 3 3


Output


3


Input


3 5
4 3 4


Output


4


Input


2 10
5 7


Output


-1

Note

<image>

You are allowed to not use all the chains, so it's optimal to only use chain of length 4 in the second example.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// source: Me, based off github/the-tourist/algo
class segtree {
public:
    struct node {
        ll val;
        ll lazyVal;
        bool identity;
        node() {
            val = lazyVal = 0;
            identity = false;
        }

        void apply(int l, int r, ll v) {
            //make sure to update lazyVal here
            val += (r - l + 1) * v;
            lazyVal += v;
        }
    };
    
    node unite(const node &a, const node &b) const {
        // combines two nodes
        if(a.identity) return b;
        if(b.identity) return a;
        node res;
        res.val = a.val + b.val;
        return res;
    }

    inline void push(int x, int l, int r) {
        // return; if no lazy prop
        // make sure to reset lazyValue here, lazy is added in apply function
        int mid = (l + r) >> 1;
        if (l != r) {
            tree[2 * x].apply(l, mid, tree[x].lazyVal);
            tree[2 * x + 1].apply(mid + 1, r, tree[x].lazyVal);
        }
        tree[x].lazyVal = 0;
    }

    inline void pull(int x) { tree[x] = unite(tree[2 * x], tree[2 * x + 1]); }

    int n;
    vector<node> tree;
    segtree(int _n) : n(_n) {
        assert(n > 0);
        tree.resize(4 * n);
        build(1, 0, n - 1);
    }
    template <typename M>
    segtree(const vector<M> &v) {
        n = v.size();
        assert(n > 0);
        tree.resize(4 * n);
        build(1, 0, n - 1, v);
    }
    node get(int ll, int rr) {
        assert(0 <= ll && ll <= rr && rr <= n - 1);
        return get(1, 0, n - 1, ll, rr);
    }
    int bS(int v){
        return bS(1, 0, n - 1, v);
    }
    template <typename... M>
    void modify(int ll, int rr, const M &... v) {
        assert(0 <= ll && ll <= rr && rr <= n - 1);
        modify(1, 0, n - 1, ll, rr, v...);
    }

private:
    void build(int x, int l, int r) {
        if (l == r) {
            return;
        }
        int mid = (l + r) >> 1;
        build(2 * x, l, mid);
        build(2 * x + 1, mid + 1, r);
        pull(x);
    }
    template <typename M>
    void build(int x, int l, int r, const vector<M> &v) {
        if (l == r) {
            tree[x].apply(l, r, v[l]);
            return;
        }
        int mid = (l + r) >> 1;
        build(2 * x, l, mid, v);
        build(2 * x + 1, mid + 1, r, v);
        pull(x);
    }
    int bS(int x, int l, int r, int v) {
        if(tree[x].val < v) return -1;
        if(l==r) return l;
        int mid = (l + r) >> 1;
        push(x, l, r); 
        int res;
        if(v <= tree[2*x].val) res = bS(2*x, l, mid, v);
        else res = bS(2*x+1, mid+1, r, v-tree[2*x].val);
        pull(x);
        return res;
    }
    node get(int x, int l, int r, int ll, int rr) {
        node res{};
        res.identity = true;
        if (ll > r || l > rr) return res;
        if (ll <= l && r <= rr) return tree[x];
        int mid = (l + r) >> 1;
        push(x, l, r);
        res = unite(get(2 * x, l, mid, ll, rr),
                    get(2 * x + 1, mid + 1, r, ll, rr));
        pull(x);
        return res;
    }
    template <typename... M>
    void modify(int x, int l, int r, int ll, int rr, const M &... v) {
        if (ll > r || l > rr) return;
        if (ll <= l && r <= rr) {
            tree[x].apply(l, r, v...);
            return;
        }
        int mid = (l + r) >> 1;
        push(x, l, r);
        modify(2 * x, l, mid, ll, rr, v...);
        modify(2 * x + 1, mid + 1, r, ll, rr, v...);
        pull(x);
    }
};
const int MAXN = 2e5;
void run_case(){
    int n, k;
    cin>>n>>k;
    vector<int> l(n); 
    ll sum = 1;
    for(int& i:l) {
        cin>>i;
        sum += i;
    }
    sum -= 2 * n;
    if(sum<k){
        cout<<"-1\n";
        return;
    }
    
    sort(l.begin(), l.end(), greater<int>());
    segtree st(2*MAXN);
    st.modify(0, 0, 1);
    int ans = -1;
    int ind = 0;
    for(int i = 0; i< n; i++){
        while(st.get(ind, ind).val==0) ind++;
        st.modify(ind, ind, -1);
        int len = l[i]/2;
        st.modify(ind+2, ind+2+len-1, 1);
        st.modify(ind+2, ind+2+(l[i]-1-len)-1, 1);
        // cout<<ind<<" "<<len<<" "<<ind+2+(l[i]-1-len)<<endl;
        // cout<<st.get(2,2).val<<endl;
        // cout<<st.get(3,3).val<<endl;
        int cur = st.bS(k);
        if(cur!=-1) {
            // cout<<i<<" "<<cur<<endl;
            if(ans==-1 || cur < ans)
                ans = cur;
        }
    }
    cout<<ans<<'\n';

}
int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    if (fopen("input.in", "r")) 
        freopen("input.in", "r", stdin), freopen("output.out", "w", stdout);
    int t;
    t=1;
    while(t--){
        run_case();
    }
}

```