#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> int2;
const int Inf = 1e9+7;
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcountll __popcnt64
#endif
#define mp make_pair
#define endl '\n'

const int N = 1e6+7;
const int M = 1e7+7;
int n, k, a[N];
ll dp[M];

ll calc(int y, int x)
{
    if (dp[y] > -1) return dp[y];
    ll& res = dp[y];
    if (y < x) return res = 0;
    if (x <= y && y < 2*x) return res = 1;
    return res = calc((y+1)/2, x)+calc(y/2, x);
}

bool check(int x)
{
    memset(dp, -1, sizeof(dp));

    ll c = 0;
    for (int i = 0; i < n; i++) {
        if (x == 1) c += a[i];
        else c += calc(a[i], x);
        if (c >= k) return true;
    }
    return false;
}

void solve()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a+n);

    int lo = 1, hi = M;
    while (lo < hi) {
        int md = (lo+hi+1)/2;
        if (check(md)) lo = md;
        else hi = md-1;
    }
    if (!check(lo)) {
        cout << "-1" << endl;
        return;
    }
    cout << lo << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(9);
    cout << fixed;

    //clock_t ts;
    //ts = clock();
    solve();
    //ts = clock()-ts;
    //cout << ts*1000.0/CLOCKS_PER_SEC << " ms" << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> int2;
const int Inf = 1e9+7;
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcountll __popcnt64
#endif
#define mp make_pair
#define endl '\n'

const int N = 1e6+7;
const int M = 1e7+7;
int n, k, a[N];
ll dp[M];

ll calc(int y, int x)
{
    if (dp[y] > -1) return dp[y];
    ll& res = dp[y];
    if (y < x) return res = 0;
    if (x <= y && y < 2*x) return res = 1;
    return res = calc((y+1)/2, x)+calc(y/2, x);
}

bool check(int x)
{
    memset(dp, -1, sizeof(dp));

    ll c = 0;
    for (int i = 0; i < n; i++) {
        if (x == 1) c += a[i];
        else c += calc(a[i], x);
    }
    return c >= k;
}

void solve()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int lo = 1, hi = 1e5+7;
    while (lo < hi) {
        int md = (lo+hi+1)/2;
        if (check(md)) lo = md;
        else hi = md-1;
    }
    if (!check(lo)) {
        cout << "-1" << endl;
        return;
    }
    cout << lo << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(9);
    cout << fixed;

    //clock_t ts;
    //ts = clock();
    solve();
    //ts = clock()-ts;
    //cout << ts*1000.0/CLOCKS_PER_SEC << " ms" << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> int2;
const int Inf = 1e9+7;
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcountll __popcnt64
#endif
#define mp make_pair
#define endl '\n'

const int N = 1e6+7;
const int M = 1e7+7;
int n, k, a[N];
ll dp[M];

ll calc(int y, int x)
{
    if (x == 1) return y;

    if (dp[y] > -1) return dp[y];
    ll& res = dp[y];
    res = 0;
    if (x <= y && y < 2*x) res = 1;
    else if (y >= 2*x) res = calc((y+1)/2, x)+calc(y/2, x);
    return res;
}

bool check(int x)
{
    ll c = 0;
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; i++) {
        c += calc(a[i], x);
        if (c >= k) return true;
    }
    return false;
}

void solve()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int lo = 1, hi = M;
    while (lo < hi) {
        int md = (lo+hi+1)/2;
        if (check(md)) lo = md;
        else hi = md-1;
    }
    if (!check(lo)) {
        cout << "-1" << endl;
        return;
    }
    cout << lo << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(9);
    cout << fixed;

    //clock_t ts;
    //ts = clock();
    solve();
    //ts = clock()-ts;
    //cout << ts*1000.0/CLOCKS_PER_SEC << " ms" << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> int2;
const int Inf = 1e9+7;
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcountll __popcnt64
#endif
#define mp make_pair
#define endl '\n'

const int N = 1e6+7;
const int M = 1e7+7;
int n, k, a[N];
ll dp[M];

ll calc(int y, int x)
{
    if (dp[y] > -1) return dp[y];
    ll& res = dp[y];
    if (x <= y && y < 2*x) return res = 1;
    else if (y >= 2*x) return res = calc((y+1)/2, x)+calc(y/2, x);
    else if (y < x) return res = 0;
}

bool check(int x)
{
    ll c = 0;
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; i++)
        c += calc(a[i], x);
    return c >= k;
}

void solve()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int lo = 1, hi = 1e7;
    while (lo < hi) {
        int md = (lo+hi+1)/2;
        if (check(md)) lo = md;
        else hi = md-1;
    }
    if (!check(lo)) {
        cout << "-1" << endl;
        return;
    }
    cout << lo << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(9);
    cout << fixed;

    //clock_t ts;
    //ts = clock();
    solve();
    //ts = clock()-ts;
    //cout << ts*1000.0/CLOCKS_PER_SEC << " ms" << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> int2;
const int Inf = 1e9+7;
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcountll __popcnt64
#endif
#define mp make_pair
#define endl '\n'

const int N = 1e6+7;
const int M = 1e7+7;
int n, k, a[N];
ll dp[M];

bool check(int x)
{
    memset(dp, 0, sizeof(dp));
    for (int y = 0; y < M; y++) {
        if (x <= y && y < 2*x) dp[y] = 1;
        else dp[y] = dp[(y+1)/2]+dp[y/2];
    }

    ll c = 0;
    for (int i = 0; i < n; i++)
        c += dp[a[i]];
    return c >= k;
}

void solve()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a+n);

    int lo = 1, hi = M;
    while (lo < hi) {
        int md = (lo+hi+1)/2;
        if (check(md)) lo = md;
        else hi = md-1;
    }
    if (!check(lo)) {
        cout << "-1" << endl;
        return;
    }
    cout << lo << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(9);
    cout << fixed;

    //clock_t ts;
    //ts = clock();
    solve();
    //ts = clock()-ts;
    //cout << ts*1000.0/CLOCKS_PER_SEC << " ms" << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> int2;
const int Inf = 1e9+7;
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcountll __popcnt64
#endif
#define mp make_pair
#define endl '\n'

const int N = 1e6+7;
const int M = 1e7+7;
int n, k, a[N];
ll dp[M];

ll calc(int y, int x)
{
    if (dp[y] > -1) return dp[y];
    ll& res = dp[y];
    res = 0;
    if (x <= y && y < 2*x) res = 1;
    else if (y == 2*x) res = 2*calc(y/2, x);
    else if (y > 2*x) res = calc((y+1)/2, x)+calc(y/2, x);
    return res;
}

bool check(int x)
{
    ll c = 0;
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; i++)
        c += calc(a[i], x);
    return c >= k;
}

void solve()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int lo = 1, hi = M;
    while (lo < hi) {
        int md = (lo+hi+1)/2;
        if (check(md)) lo = md;
        else hi = md-1;
    }
    if (!check(lo)) {
        cout << "-1" << endl;
        return;
    }
    cout << lo << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(9);
    cout << fixed;

    //clock_t ts;
    //ts = clock();
    solve();
    //ts = clock()-ts;
    //cout << ts*1000.0/CLOCKS_PER_SEC << " ms" << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> int2;
const int Inf = 1e9+7;
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcountll __popcnt64
#endif
#define mp make_pair
#define endl '\n'

const int N = 1e6+7;
const int M = 1e7+7;
int n, k, a[N];
ll dp[M];

ll calc(int y, int x)
{
    if (dp[y] > -1) return dp[y];
    ll& res = dp[y];
    res = 0;
    if (x <= y && y < 2*x) res = 1;
    else if (y >= 2*x) res = calc((y+1)/2, x)+calc(y/2, x);
    return res;
}

bool check(int x)
{
    ll c = 0;
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; i++) {
        if (x == 1) c += a[i];
        else c += calc(a[i], x);
        if (c >= k) return true;
    }
    return false;
}

void solve()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int lo = 1, hi = M;
    while (lo < hi) {
        int md = (lo+hi+1)/2;
        if (check(md)) lo = md;
        else hi = md-1;
    }
    if (!check(lo)) {
        cout << "-1" << endl;
        return;
    }
    cout << lo << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(9);
    cout << fixed;

    //clock_t ts;
    //ts = clock();
    solve();
    //ts = clock()-ts;
    //cout << ts*1000.0/CLOCKS_PER_SEC << " ms" << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> int2;
const int Inf = 1e9+7;
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcountll __popcnt64
#endif
#define mp make_pair
#define endl '\n'

const int N = 1e6+7;
const int M = 1e7+7;
int n, k, a[N];
ll dp[M];

ll calc(int y, int x)
{
    if (dp[y] > -1) return dp[y];
    ll& res = dp[y];
    if (y < x) return res = 0;
    if (x <= y && y < 2*x) return res = 1;
    return res = calc((y+1)/2, x)+calc(y/2, x);
}

bool check(int x)
{
    memset(dp, -1, sizeof(dp));

    ll c = 0;
    for (int i = 0; i < n; i++) {
        if (x == 1) c += a[i];
        else c += calc(a[i], x);
    }
    return c >= k;
}

void solve()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int lo = 1, hi = 1e6+7;
    while (lo < hi) {
        int md = (lo+hi+1)/2;
        if (check(md)) lo = md;
        else hi = md-1;
    }
    if (!check(lo)) {
        cout << "-1" << endl;
        return;
    }
    cout << lo << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(9);
    cout << fixed;

    //clock_t ts;
    //ts = clock();
    solve();
    //ts = clock()-ts;
    //cout << ts*1000.0/CLOCKS_PER_SEC << " ms" << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> int2;
const int Inf = 1e9+7;
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcountll __popcnt64
#endif
#define mp make_pair
#define endl '\n'

const int N = 1e6+7;
const int M = 1e7+7;
int n, k, a[N];
ll dp[M];

ll calc(int y, int x)
{
    if (dp[y] > -1) return dp[y];
    ll& res = dp[y];
    res = 0;
    if (x <= y && y < 2*x) res = 1;
    else if (y >= 2*x) res = calc((y+1)/2, x)+calc(y/2, x);
    return res;
}

bool check(int x)
{
    ll c = 0;
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; i++) {
        c += calc(a[i], x);
        if (c >= k) return true;
    }
    return false;
}

void solve()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int lo = 1, hi = M;
    while (lo < hi) {
        int md = (lo+hi+1)/2;
        if (check(md)) lo = md;
        else hi = md-1;
    }
    if (!check(lo)) {
        cout << "-1" << endl;
        return;
    }
    cout << lo << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(9);
    cout << fixed;

    //clock_t ts;
    //ts = clock();
    solve();
    //ts = clock()-ts;
    //cout << ts*1000.0/CLOCKS_PER_SEC << " ms" << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> int2;
const int Inf = 1e9+7;
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcountll __popcnt64
#endif
#define mp make_pair
#define endl '\n'

const int N = 1e6+7;
const int M = 1e7+7;
int n, k, a[N];
ll dp[M];

ll calc(int y, int x)
{
    if (dp[y] > -1) return dp[y];
    ll& res = dp[y];
    if (y < x) return res = 0;
    if (x <= y && y < 2*x) return res = 1;
    return res = calc((y+1)/2, x)+calc(y/2, x);
}

bool check(int x)
{
    memset(dp, -1, sizeof(dp));

    ll c = 0;
    for (int i = 0; i < n; i++) {
        if (x == 1) c += a[i];
        else c += calc(a[i], x);
    }
    return c >= k;
}

void solve()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int lo = 1, hi = M;
    while (lo < hi) {
        int md = (lo+hi+1)/2;
        if (check(md)) lo = md;
        else hi = md-1;
    }
    if (!check(lo)) {
        cout << "-1" << endl;
        return;
    }
    cout << lo << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(9);
    cout << fixed;

    //clock_t ts;
    //ts = clock();
    solve();
    //ts = clock()-ts;
    //cout << ts*1000.0/CLOCKS_PER_SEC << " ms" << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> int2;
const int Inf = 1e9+7;
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcountll __popcnt64
#endif
#define mp make_pair
#define endl '\n'

const int N = 1e6+7;
const int M = 1e7+7;
int n, k, a[N];
int dp[M];

int calc(int y, int x)
{
    if (dp[y] > -1) return dp[y];
    int& res = dp[y];
    if (x <= y && y < 2*x) return res = 1;
    else if (y >= 2*x) return res = calc((y+1)/2, x)+calc(y/2, x);
    else if (y < x) return res = 0;
}

bool check(int x)
{
    int c = 0;
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; i++)
        c += calc(a[i], x);
    return c >= k;
}

void solve()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int lo = 1, hi = 1e7;
    while (lo < hi) {
        int md = (lo+hi+1)/2;
        if (check(md)) lo = md;
        else hi = md-1;
    }
    if (!check(lo)) {
        cout << "-1" << endl;
        return;
    }
    cout << lo << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(9);
    cout << fixed;

    //clock_t ts;
    //ts = clock();
    solve();
    //ts = clock()-ts;
    //cout << ts*1000.0/CLOCKS_PER_SEC << " ms" << endl;

    return 0;
}


//g++ -std=c++11 -g -O2 -o ./a ./A.cpp
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define rz resize
#define nl '\n'
typedef long long ll;
typedef pair<int,int> pii;
////////////////////////////////////////////////////////////////////////////////

int n , k;
int a[1000100];
int h[10001000];//

int parts;
void spl(int i){
  h[i/2] += h[i];
  h[i-i/2]+=h[i];
  parts += h[i];
  h[i]=0;
}

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

  cin>>n>>k;

  parts=n;
  int mx = 0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    h[a[i]]++;
    mx=max(mx,a[i]);
  }

  int ans = 0;
  while(parts-h[ans]>=k)parts-=h[ans++];

  if(n>=k){
    cout<<ans<<nl;
    return 0;
  }

  for(int i=mx;i>=ans;--i){
    //cerr<<i<<endl;
    if(h[i]==0)continue;
    if(i/2>=ans){
      spl(i);
      while(parts-h[ans]>=k)parts-=h[ans++];
    }else if(parts<k){
      while(ans>i/2)parts+=h[--ans];
      spl(i);
    }
  }

  cout<<ans<<nl;

  return 0;
};


//g++ -std=c++11 -g -O2 -o ./a ./A.cpp
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define rz resize
#define nl '\n'
typedef long long ll;
typedef pair<int,int> pii;
////////////////////////////////////////////////////////////////////////////////

int n , k;
int a[1000100];
const int nn = 10001000;
int h[10001000];//

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

  cin>>n>>k;

  ll ts=0;
  int mx = 0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    ts+=a[i];
    h[a[i]]++;
    mx=max(mx,a[i]);
  }

  if(ts<k){cout<<-1<<nl;return 0;}

  int ans = nn-1, parts=0;
  if(n>=k){
    for(int parts=0;parts<k;ans--)
      parts+=h[ans];
    cout<<ans<<nl;
    return 0;
  }

  parts = n;
  ans = *min_element(a+1,a+n+1);

  while(mx/2>=ans){
    parts += h[mx];
    h[mx/2]+=h[mx];h[mx-mx/2]+=h[mx];
    mx--;
    while(parts-h[ans]>=k)parts-=h[ans++];
  }

  cout<<ans<<nl;

  return 0;
};


//g++ -std=c++11 -g -O2 -o ./a ./A.cpp
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define rz resize
#define nl '\n'
typedef long long ll;
typedef pair<int,int> pii;
////////////////////////////////////////////////////////////////////////////////

const int nn = (int)1e7;
ll n,k,h[nn+100];

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

  cin>>n>>k;
  memset(h,0,sizeof h);
  ll tot = 0;
  for(int i=1;i<=n;i++){
    int x;cin>>x;
    h[x]++;tot+=x;
  }

  if(tot<k){
    cout<<-1<<nl;
    return 0;
  }

  if(n>=k){
    for(int parts=0,i=nn;i>=1;i--){
      parts+=h[i];
      if(parts>=k){cout<<i<<nl;break;}
    }
    return 0;
  }

  ll ans = 1, parts = n, i;
  for(;h[ans]==0;ans++);

  for(i=nn;i>=1 and parts<k;i--){
    if(h[i]==0)continue;
    h[i/2] += h[i], h[(1+i)/2] += h[i];parts += h[i];h[i]=0;
    ans = min(ans,i/2);
  }

  for(;i>=ans;i--){
    if(h[i]==0)continue;
    if(i/2<ans)break;
    h[i/2] += h[i], h[(1+i)/2] += h[i];parts += h[i];h[i]=0;
    while(parts-h[ans]>=k)parts-=h[ans++];
  }

  //for(ll total = 0,x=ans;x<=i;x++){total += h[x];cerr<<x<<" "<<h[x]<<" ..." << total << endl;}

  cout<<ans<<nl;

  return 0;
};


//g++ -std=c++11 -g -O2 -o ./a ./A.cpp
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define rz resize
#define nl '\n'
typedef long long ll;
typedef pair<int,int> pii;
////////////////////////////////////////////////////////////////////////////////

const int nn = (int)1e7;
ll n,k;
ll h[10001000];
ll dp[nn+100];

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

  cin>>n>>k;

  int lo=-1,hi=0,mid;
  for(int a,i=1;i<=n;i++){
    cin>>a;
    h[a]++;
    hi=max(hi,a);
  }
  int mx = hi;

  while(lo<hi){
    mid=(lo+hi+1)/2;

    fill(dp+mid,dp+mx+1,0);
    ll tot=0;
    for(int i=mx;i>=mid;i--){
      dp[i]+=h[i];
      if(i/2>=mid)dp[i/2]+=dp[i],dp[i-i/2]+=dp[i];
      else tot += dp[i];
    }

    if(tot>=k)lo=mid;
    else hi=mid-1;
  }

  cout<<lo<<nl;

  return 0;
};


//g++ -std=c++11 -g -O2 -o ./a ./A.cpp
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define rz resize
#define nl '\n'
typedef long long ll;
typedef pair<int,int> pii;
////////////////////////////////////////////////////////////////////////////////

int n , k;
int a[1000100];

multiset<int> m;

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

  cin>>n>>k;
  for(int i=1;i<=n;i++)cin>>a[i];

  for(int i=1;i<=n;i++)
    m.insert(a[i]);

  if(m.size()>k){
    while(m.size()>k)m.erase(m.find(*m.begin()));
    cout<<*m.begin()<<nl;
    return 0;
  }

  while(m.size()<k){
    auto it = --m.end();
    int v = *it;
    m.erase(m.find(*it));
    if(v==1)break;
    m.insert(v/2),m.insert(v-v/2);///
  }

  //for(auto&it:m)cerr<<it<<' ';cerr<<endl;

  int ans = (m.size()>=k)?*m.begin():-1;
  cout<<ans<<nl;

  return 0;
};


//g++ -std=c++11 -g -O2 -o ./a ./A.cpp
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define rz resize
#define nl '\n'
typedef long long ll;
typedef pair<int,int> pii;
////////////////////////////////////////////////////////////////////////////////

int n , k;
int a[1000100];
int h[10001000];//

int parts;
void spl(int i){
  h[i/2] += h[i];
  h[i-i/2]+=h[i];
  parts += h[i];
  h[i]=0;
}

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

  cin>>n>>k;

  parts=n;
  int mx = 0;
  ll ts=0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    ts+=a[i];
    h[a[i]]++;
    mx=max(mx,a[i]);
  }

  if(ts<k){cout<<-1<<nl;return 0;}

  int ans = 1;
  while(parts-h[ans]>=k)parts-=h[ans++];

  if(n>=k){
    cout<<ans<<nl;
    return 0;
  }

  for(int i=mx;i>=ans;--i){
    //cerr<<i<<endl;
    if(h[i]==0)continue;
    if(i/2>=ans){
      spl(i);
      while(parts-h[ans]>=k)parts-=h[ans++];
    }else if(parts<k){
      while(ans>i/2)parts+=h[--ans];
      spl(i);
    }
  }

  cout<<ans<<nl;

  return 0;
};


//g++ -std=c++11 -g -O2 -o ./a ./A.cpp
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define rz resize
#define nl '\n'
typedef long long ll;
typedef pair<int,int> pii;
////////////////////////////////////////////////////////////////////////////////

int n , k;
int a[1000100];
multiset<int> m;

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

  cin>>n>>k;
  for(int i=1;i<=n;i++)cin>>a[i];

  for(int i=1;i<=n;i++)
    m.insert(a[i]);

  if(m.size()>k){
    while(m.size()>k)m.erase(m.find(*m.begin()));
    cout<<*m.begin()<<nl;
    return 0;
  }

  while(m.size()<k){
    auto it = --m.end();
    int v = *it;
    m.erase(m.find(*it));
    if(v==1)break;
    m.insert(v/2),m.insert(1+v/2);
  }

  int ans = (m.size()>=k)?*m.begin():-1;
  cout<<ans<<nl;

  return 0;
};


//g++ -std=c++11 -g -O2 -o ./a ./A.cpp
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define rz resize
#define nl '\n'
typedef long long ll;
typedef pair<int,int> pii;
////////////////////////////////////////////////////////////////////////////////

ll n,k,h[10001000],dp[10001000];

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

  cin>>n>>k;
  int mx=0;ll tot=0;
  for(int a,i=1;i<=n;i++){
    cin>>a;h[a]++;
    mx=max(mx,a);
    tot+=a;
  }

  if(tot<k){
    cout<<-1<<nl;
    return 0;
  }

  ll lo=1,hi=mx,mid;
  while(lo<hi){
    mid = (lo+hi+1)/2;

    ll total = 0;
    for(ll j=mx;j>=mid;j--){
      dp[j]+=h[j];
      if(j/2 >= mid){
	dp[j/2] += dp[j], dp[(1+j)/2]+=dp[j];
      }else total += dp[j];
      dp[j]=0;
    }

    //cerr << "$" << mid << ',' << total << endl;

    if(total >= k)lo=mid;
    else hi=mid-1;
  }

  cout<<lo<<nl;

  return 0;
};


//g++ -std=c++11 -g -O2 -o ./a ./A.cpp
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define rz resize
#define nl '\n'
typedef long long ll;
typedef pair<int,int> pii;
////////////////////////////////////////////////////////////////////////////////

const int nn = (int)1e7;
ll n,k;
ll h[10001000];
ll dp[nn+100];

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

  cin>>n>>k;

  int lo=-1,hi=0,mid;
  for(int a,i=1;i<=n;i++){
    cin>>a;
    h[a]++;
    hi=max(hi,a);
  }
  int mx = hi;

  while(lo<hi){
    mid=(lo+hi+1)/2;

    memset(dp,0,sizeof dp);
    ll tot=0;
    for(int i=mx;i>=mid;i--){
      dp[i]+=h[i];
      if(i/2>=mid)dp[i/2]+=dp[i],dp[i-i/2]+=dp[i];
      else tot += dp[i];
    }

    if(tot>=k)lo=mid;
    else hi=mid-1;
  }

  cout<<lo<<nl;

  return 0;
};


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pii pair<int, int>
#define pll pair<long long, long long>
#define V  vector
#define pb  push_back
#define mp  make_pair
#define pq priority_queue
#define FIN(x) freopen(x,"r",stdin)
#define FOUT(x) freopen(x,"w",stdout)
#define ALL(x) x.begin(),x.end()
#define M(a,x) memset(a,x,sizeof(a))
#define sci(x) scanf("%d",&x);
#define scl(x) scanf("%lld",&x);
#define scs(x) scanf("%s",x);
#define SZ(x) (int)x.size()
#define print(x) printf("%d",x);
#define nl printf("\n")
#define fr first
#define se second
#define printl(x) printf("%lld",x)
#define F(i,a,n) for(int i=a;i<n;i++)
#define INF 4000000000000000000LL
#define LL long long

const int N = 1e6+5;
int n,k;
int a[N];
int dp[10000007];
int rec(int val,int mid) {
	if(val < mid) {
		return 0;
	}
	if(val < 2*mid){
		return 1;
	}
	if(dp[val] != -1) return dp[val];
	return dp[val] = rec(val/2,mid) + rec(val-val/2,mid);
}
bool f(int mid){
	long long ret = 0;
	for(int i = 0 ; i < n ; i++){
		int val = a[i];
		if(val < mid) continue;
		ret += rec(val,mid);
	}
	return (ret >= k);
}
int main() {
	M(dp,-1);
	cin >> n >> k;
	int mx = -1;
	for(int i = 0 ; i < n ; i++){
		sci(a[i]);
		mx = max(mx,a[i]);
	}
	int ans = -1;
	int low = 1;
	int high = mx;;

	while(low <= high){
		int mid = (low + high)/2;
		if(f(mid)){
			ans = mid;
			low = mid+1;
		}
		else {
			high = mid-1;
		}
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pii pair<int, int>
#define pll pair<long long, long long>
#define V  vector
#define pb  push_back
#define mp  make_pair
#define pq priority_queue
#define FIN(x) freopen(x,"r",stdin)
#define FOUT(x) freopen(x,"w",stdout)
#define ALL(x) x.begin(),x.end()
#define M(a,x) memset(a,x,sizeof(a))
#define sci(x) scanf("%d",&x);
#define scl(x) scanf("%lld",&x);
#define scs(x) scanf("%s",x);
#define SZ(x) (int)x.size()
#define print(x) printf("%d",x);
#define nl printf("\n")
#define fr first
#define se second
#define printl(x) printf("%lld",x)
#define F(i,a,n) for(int i=a;i<n;i++)
#define INF 4000000000000000000LL
#define LL long long

const int N = 1e6+5;
int n,k;
int a[N];
int f[10000007];
int cnt[10000007];
bool poss(int mid){
	for(int i = mid ; i<= 10000000 ; i++){
		f[i] = cnt[i];
	}
	for(int i = 10000000 ; i>= mid ; i--){
		int a = i/2;
		int b = i-a;
		if(b < mid) break;
		f[a] += f[i];
		f[b] += f[i];
		f[i] = 0;
	}
	long long sum = 0;
	for(int i = mid ; i<= 10000000 ; i++){
		sum += f[i];
	}
	return (sum >= k);
}
int main() {
	cin >> n >> k;
	int mx = -1;
	long long sum = 0;
	for(int i = 0 ; i < n ; i++){
		sci(a[i]);
		mx = max(mx,a[i]);
		cnt[a[i]]++;
	}
	int ans = -1;
	int low = 1;
	int high = mx;;
	while(low <= high){
		int mid = (low + high)/2;
		if(poss(mid)){
			ans = mid;
			low = mid+1;
		}
		else {
			high = mid-1;
		}
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pii pair<int, int>
#define pll pair<long long, long long>
#define V  vector
#define pb  push_back
#define mp  make_pair
#define pq priority_queue
#define FIN(x) freopen(x,"r",stdin)
#define FOUT(x) freopen(x,"w",stdout)
#define ALL(x) x.begin(),x.end()
#define M(a,x) memset(a,x,sizeof(a))
#define sci(x) scanf("%d",&x);
#define scl(x) scanf("%lld",&x);
#define scs(x) scanf("%s",x);
#define SZ(x) (int)x.size()
#define print(x) printf("%d",x);
#define nl printf("\n")
#define fr first
#define se second
#define printl(x) printf("%lld",x)
#define F(i,a,n) for(int i=a;i<n;i++)
#define INF 4000000000000000000LL
#define LL long long

const int N = 1e6+5;
int n,k;
int a[N];
int rec(int val,int mid) {
	if(val < mid) {
		return 0;
	}
	if(val < 2*mid){
		return 1;
	}
	if(val % 2 == 0){
	   return 2*rec(val/2,mid);
	}
	else {
		return rec(val/2,mid) + rec(val-val/2,mid);
	}
}
bool f(int mid){
	long long ret = 0;
	for(int i = 0 ; i < n ; i++){
		int val = a[i];
		if(val < mid) continue;
		ret += rec(val,mid);
	}
	return (ret >= k);
}
int main() {
	cin >> n >> k;
	int mx = -1;
	long long sum = 0;
	for(int i = 0 ; i < n ; i++){
		sci(a[i]);
		sum += a[i];
		mx = max(mx,a[i]);
	}
	if(sum < k){
		cout << -1 << endl;
		return 0;
	}
	int ans = -1;
	int low = 1;
	int high = mx;;

	while(low <= high){
		int mid = (low + high)/2;
		if(f(mid)){
			ans = mid;
			low = mid+1;
		}
		else {
			high = mid-1;
		}
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pii pair<int, int>
#define pll pair<long long, long long>
#define V  vector
#define pb  push_back
#define mp  make_pair
#define pq priority_queue
#define FIN(x) freopen(x,"r",stdin)
#define FOUT(x) freopen(x,"w",stdout)
#define ALL(x) x.begin(),x.end()
#define M(a,x) memset(a,x,sizeof(a))
#define sci(x) scanf("%d",&x);
#define scl(x) scanf("%lld",&x);
#define scs(x) scanf("%s",x);
#define SZ(x) (int)x.size()
#define print(x) printf("%d",x);
#define nl printf("\n")
#define fr first
#define se second
#define printl(x) printf("%lld",x)
#define F(i,a,n) for(int i=a;i<n;i++)
#define INF 4000000000000000000LL
#define LL long long

const int N = 1e6+5;
int n,k;
int a[N];
long long f[10000007];
long long  cnt[10000007];
bool poss(int mid){
	for(int i = mid ; i<= 10000000 ; i++){
		f[i] = cnt[i];
	}
	for(int i = 10000000 ; i>= mid ; i--){
		int a = i/2;
		int b = i-a;
		if(a < mid) break;
		f[a] += f[i];
		f[b] += f[i];
		f[i] = 0;
	}
	long long sum = 0;
	for(int i = mid ; i<= 10000000 ; i++){
		sum += f[i];
	}
	return (sum >= k);
}
int main() {
	cin >> n >> k;
	int mx = -1;
	long long sum = 0;
	for(int i = 0 ; i < n ; i++){
		sci(a[i]);
		mx = max(mx,a[i]);
		cnt[a[i]]++;
	}
	int ans = -1;
	int low = 1;
	int high = mx;;
	while(low <= high){
		int mid = (low + high)/2;
		if(poss(mid)){
			ans = mid;
			low = mid+1;
		}
		else {
			high = mid-1;
		}
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pii pair<int, int>
#define pll pair<long long, long long>
#define V  vector
#define pb  push_back
#define mp  make_pair
#define pq priority_queue
#define FIN(x) freopen(x,"r",stdin)
#define FOUT(x) freopen(x,"w",stdout)
#define ALL(x) x.begin(),x.end()
#define M(a,x) memset(a,x,sizeof(a))
#define sci(x) scanf("%d",&x);
#define scl(x) scanf("%lld",&x);
#define scs(x) scanf("%s",x);
#define SZ(x) (int)x.size()
#define print(x) printf("%d",x);
#define nl printf("\n")
#define fr first
#define se second
#define printl(x) printf("%lld",x)
#define F(i,a,n) for(int i=a;i<n;i++)
#define INF 4000000000000000000LL
#define LL long long

const int N = 1e6+5;
int n,k;
int a[N];
int rec(int val,int mid) {
	if(val < mid) {
		return 0;
	}
	if(val < 2*mid){
		return 1;
	}
	if(val % 2 == 0){
	   return 2*rec(val/2,mid);
	}
	else {
		return rec(val/2,mid) + rec(val-val/2,mid);
	}
}
bool f(int mid){
	long long ret = 0;
	for(int i = 0 ; i < n ; i++){
		int val = a[i];
		if(val < mid) continue;
		ret += rec(val,mid);
	}
	return (ret >= k);
}
int main() {
	cin >> n >> k;
	int mx = -1;
	int sum = 0;
	for(int i = 0 ; i < n ; i++){
		sci(a[i]);
		sum += a[i];
		mx = max(mx,a[i]);
	}
	if(sum < k){
		cout << -1 << endl;
		return 0;
	}
	int ans = -1;
	int low = 1;
	int high = mx;;

	while(low <= high){
		int mid = (low + high)/2;
		if(f(mid)){
			ans = mid;
			low = mid+1;
		}
		else {
			high = mid-1;
		}
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pii pair<int, int>
#define pll pair<long long, long long>
#define V  vector
#define pb  push_back
#define mp  make_pair
#define pq priority_queue
#define FIN(x) freopen(x,"r",stdin)
#define FOUT(x) freopen(x,"w",stdout)
#define ALL(x) x.begin(),x.end()
#define M(a,x) memset(a,x,sizeof(a))
#define sci(x) scanf("%d",&x);
#define scl(x) scanf("%lld",&x);
#define scs(x) scanf("%s",x);
#define SZ(x) (int)x.size()
#define print(x) printf("%d",x);
#define nl printf("\n")
#define fr first
#define se second
#define printl(x) printf("%lld",x)
#define F(i,a,n) for(int i=a;i<n;i++)
#define INF 4000000000000000000LL
#define LL long long

const int N = 1e6+5;
int n,k;
int a[N];
int rec(int val,int mid) {
	if(val < mid) {
		return 0;
	}
	if(val < 2*mid){
		return 1;
	}
	return rec(val/2,mid) + rec(val-val/2,mid);
}
bool f(int mid){
	long long ret = 0;
	for(int i = 0 ; i < n ; i++){
		int val = a[i];
		if(val < mid) continue;
		ret += rec(val,mid);
	}
	return (ret >= k);
}
int main() {
	cin >> n >> k;
	int mx = -1;
	for(int i = 0 ; i < n ; i++){
		sci(a[i]);
		mx = max(mx,a[i]);
	}
	int ans = -1;
	int low = 1;
	int high = mx;;

	while(low <= high){
		int mid = (low + high)/2;
		if(f(mid)){
			ans = mid;
			low = mid+1;
		}
		else {
			high = mid-1;
		}
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pii pair<int, int>
#define pll pair<long long, long long>
#define V  vector
#define pb  push_back
#define mp  make_pair
#define pq priority_queue
#define FIN(x) freopen(x,"r",stdin)
#define FOUT(x) freopen(x,"w",stdout)
#define ALL(x) x.begin(),x.end()
#define M(a,x) memset(a,x,sizeof(a))
#define sci(x) scanf("%d",&x);
#define scl(x) scanf("%lld",&x);
#define scs(x) scanf("%s",x);
#define SZ(x) (int)x.size()
#define print(x) printf("%d",x);
#define nl printf("\n")
#define fr first
#define se second
#define printl(x) printf("%lld",x)
#define F(i,a,n) for(int i=a;i<n;i++)
#define INF 4000000000000000000LL
#define LL long long

const int N = 1e6+5;
int n,k;
int a[N];
int rec(int val,int mid){
	int a = val/2;
	int b = val-a;
	if(a >= mid && b >= mid){
		return 2 + rec(a,mid) + rec(b,mid);
	}
	else if ( b >= mid){
		return 1;
	}
	return 0;
}
bool f(int mid){
	long long ret = 0;
	for(int i = 0 ; i < n ; i++){
		int val = a[i];
		if(val < mid) continue;
		if(val >= 2*mid) {
		  ret += rec(val,mid);
		}
		else {
			ret++;
		}
	}
	return (ret >= k);
}
int main() {
	cin >> n >> k;
	int mx = -1;
	for(int i = 0 ; i < n ; i++){
		sci(a[i]);
		mx = max(mx,a[i]);
	}
	int ans = -1;
	int low = 1;
	int high = mx;
	while(low <= high){
		int mid = (low + high)/2;
		if(f(mid)){
			ans = mid;
			low = mid+1;
		}
		else {
			high = mid-1;
		}
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pii pair<int, int>
#define pll pair<long long, long long>
#define V  vector
#define pb  push_back
#define mp  make_pair
#define pq priority_queue
#define FIN(x) freopen(x,"r",stdin)
#define FOUT(x) freopen(x,"w",stdout)
#define ALL(x) x.begin(),x.end()
#define M(a,x) memset(a,x,sizeof(a))
#define sci(x) scanf("%d",&x);
#define scl(x) scanf("%lld",&x);
#define scs(x) scanf("%s",x);
#define SZ(x) (int)x.size()
#define print(x) printf("%d",x);
#define nl printf("\n")
#define fr first
#define se second
#define printl(x) printf("%lld",x)
#define F(i,a,n) for(int i=a;i<n;i++)
#define INF 4000000000000000000LL
#define LL long long

const int N = 1e6+5;
int n,k;
int a[N];
long long f[10000007];
long long  cnt[10000007];
bool poss(int mid){
	for(int i = mid ; i<= 10000000 ; i++){
		f[i] = cnt[i];
	}
	for(int i = 10000000 ; i>= mid ; i--){
		int a = i/2;
		int b = i-a;
		if(b < mid) break;
		f[a] += f[i];
		f[b] += f[i];
		f[i] = 0;
	}
	long long sum = 0;
	for(int i = mid ; i<= 10000000 ; i++){
		sum += f[i];
	}
	return (sum >= k);
}
int main() {
	cin >> n >> k;
	int mx = -1;
	long long sum = 0;
	for(int i = 0 ; i < n ; i++){
		sci(a[i]);
		mx = max(mx,a[i]);
		cnt[a[i]]++;
	}
	int ans = -1;
	int low = 1;
	int high = mx;;
	while(low <= high){
		int mid = (low + high)/2;
		if(poss(mid)){
			ans = mid;
			low = mid+1;
		}
		else {
			high = mid-1;
		}
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pii pair<int, int>
#define pll pair<long long, long long>
#define V  vector
#define pb  push_back
#define mp  make_pair
#define pq priority_queue
#define FIN(x) freopen(x,"r",stdin)
#define FOUT(x) freopen(x,"w",stdout)
#define ALL(x) x.begin(),x.end()
#define M(a,x) memset(a,x,sizeof(a))
#define sci(x) scanf("%d",&x);
#define scl(x) scanf("%lld",&x);
#define scs(x) scanf("%s",x);
#define SZ(x) (int)x.size()
#define print(x) printf("%d",x);
#define nl printf("\n")
#define fr first
#define se second
#define printl(x) printf("%lld",x)
#define F(i,a,n) for(int i=a;i<n;i++)
#define INF 4000000000000000000LL
#define LL long long

const int N = 1e6+5;
int n,k;
int a[N];
int rec(int val,int mid) {
	if(val < mid) {
		return 0;
	}
	if(val < 2*mid){
		return 1;
	}
	if(val % 2 == 0){
	   return 2*rec(val/2,mid);
	}
	else {
		return rec(val/2,mid) + rec(val-val/2,mid);
	}
}
bool f(int mid){
	long long ret = 0;
	for(int i = 0 ; i < n ; i++){
		int val = a[i];
		if(val < mid) continue;
		ret += rec(val,mid);
	}
	return (ret >= k);
}
int main() {
	cin >> n >> k;
	int mx = -1;
	for(int i = 0 ; i < n ; i++){
		sci(a[i]);
		mx = max(mx,a[i]);
	}
	int ans = -1;
	int low = 1;
	int high = mx;;

	while(low <= high){
		int mid = (low + high)/2;
		if(f(mid)){
			ans = mid;
			low = mid+1;
		}
		else {
			high = mid-1;
		}
	}
	cout << ans << endl;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <iomanip>          //cout <<fixed<<setprecision(4) <<ans <<endl;
using namespace std;

const int M = 1000000000 +7;
typedef long long ll;
typedef unsigned long long ull;
#define  mem(a) memset(a,0,sizeof a)
#define pi acos(-1.0)
#define inf 0x3f3f3f3f //1.7e9
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const double eps = 1e-10;
const int maxn = 1e6 +5;
const int maxm = 1e7 +5;
int a[maxn],n; ll k;
int f[maxm];
ll getsum(int x,int low) {
        if(x < low) return 0;
        else if(x < 2*low) return 1;
        else return getsum(x/2,low) + getsum(x- x/2,low);
}
bool judge(int x ) {
        ll cnt = 0;
        int i = 0;
        while(i < n && a[i] >= x) {
                cnt += getsum(a[i++],x);
                if(cnt >= k)
                        return true;
                i++;
        }
        if(cnt >= k ) return true;
        return false;
}
int cmp(int a,int b) {
        return a >b;
}
int main(){
        int l = 1,r ;
        scanf("%d %I64d",&n,&k);
        for(int i = 0 ; i < n ; i ++) {
                scanf("%d",&a[i]);
        }
        sort(a,a+n,cmp);
        r = a[0];
        int ans = -1;
        while(l < r) {
              //  cout <<l<<"   "<<r <<endl;
                int m = (l+r) >> 1;
                mem(f);
                for(int i = m ; i <= a[0] ; i ++)
                        f[i] = max(1 , f[i/2] + f[i-i/2] );
                ll cnt = 0;
                for(int i = 0 ; i < n ; i ++)
                        cnt += f[a[i]];

                if(cnt >= k)  l = m+1,ans = m;
                else r = m -1;
        }
          printf("%d\n",ans);
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <iomanip>          //cout <<fixed<<setprecision(4) <<ans <<endl;
using namespace std;

const int M = 1000000000 +7;
typedef long long ll;
typedef unsigned long long ull;
#define  mem(a) memset(a,0,sizeof a)
#define pi acos(-1.0)
#define inf 0x3f3f3f3f //1.7e9
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const double eps = 1e-10;
const int maxn = 1e6 +5;
int a[maxn],n,k;
int cnt ;
bool judge(int x ) {
        cnt = 0;
        int i = 0;
        while(i < n && a[i] >= x) {
                int base = 1;
                while(a[i] / base >= x) base <<= 1;
                cnt += base / 2 ;
                if(cnt >= k)
                        return true;
                i++;
        }
        if(cnt >= k ) return true;
        return false;
}
int cmp(int a,int b) {
        return a >b;
}
int main(){
        int l = 1,r = 10000;
        scanf("%d %d",&n,&k);
        for(int i = 0 ; i < n ; i ++) {
                scanf("%d",&a[i]);
        }
        sort(a,a+n,cmp);
        int ans = inf;
        if(k <= n) {
                ans = a[k-1];
                l = ans;
        }
        while(l < r) {
                int m = (l+r+1) >> 1;
                if(judge(m)) {
                        l = m;
                }
                else r = m -1;
        }

        if(judge(l)) {
                for(int i = 0 ; i < n ; i ++) {
                        int tmp = a[i];
                        while(tmp >= l) {
                                ans = min(ans,tmp);
                                tmp /= 2;
                        }
                }
        }
        if(ans != inf) printf("%d\n",ans);
        else puts("-1");

}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <iomanip>          //cout <<fixed<<setprecision(4) <<ans <<endl;
using namespace std;

const int M = 1000000000 +7;
typedef long long ll;
typedef unsigned long long ull;
#define  mem(a) memset(a,0,sizeof a)
#define pi acos(-1.0)
#define inf 0x3f3f3f3f //1.7e9
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const double eps = 1e-10;
const int maxn = 1e6 +5;
const int maxm = 1e7 +5;
int a[maxn],n; ll k;
int f[maxm];
ll getsum(int x,int low) {
        if(x < low) return 0;
        else if(x < 2*low) return 1;
        else return getsum(x/2,low) + getsum(x- x/2,low);
}
bool judge(int x ) {
        ll cnt = 0;
        int i = 0;
        while(i < n && a[i] >= x) {
                cnt += getsum(a[i++],x);
                if(cnt >= k)
                        return true;
                i++;
        }
        if(cnt >= k ) return true;
        return false;
}
int cmp(int a,int b) {
        return a >b;
}
int main(){
        int l = 1,r ;
        scanf("%d %I64d",&n,&k);
        for(int i = 0 ; i < n ; i ++) {
                scanf("%d",&a[i]);
        }
        sort(a,a+n,cmp);
        r = a[0];
        int ans = -1;
        while(l <= r) {
              //  cout <<l<<"   "<<r <<endl;
                int m = (l+r) >> 1;
                mem(f);
                for(int i = m ; i <= a[0] ; i ++)
                        f[i] = max(1 , f[i/2] + f[i-i/2] );
                ll cnt = 0;
                for(int i = 0 ; i < n ; i ++)
                        cnt += f[a[i]];

                if(cnt >= k)  l = m+1,ans = m;
                else r = m -1;
        }
        printf("%d\n",ans);
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <iomanip>          //cout <<fixed<<setprecision(4) <<ans <<endl;
using namespace std;

const int M = 1000000000 +7;
typedef long long ll;
typedef unsigned long long ull;
#define  mem(a) memset(a,0,sizeof a)
#define pi acos(-1.0)
#define inf 0x3f3f3f3f //1.7e9
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const double eps = 1e-10;
const int maxn = 1e6 +5;
int a[maxn],n,k;
int c ;
void getsum(int x,int low) {
       // cout <<"x:  " <<x <<"   low: "<<low<<endl;
        if(x < low) return ;
        else if(x >= low && x <2* low) {
                c++;
                return ;
        }
        else if(x >= 2*low) {
                getsum( x/2 , low) ;
                getsum(x - (x/2),low);
                return ;
        }
        return ;
}
bool judge(int x ) {
       // cout <<"x : "<<x<<endl;
        int cnt = 0;
        int i = 0;
        while(i < n) {
                c = 0;
                getsum(a[i],x);
                cnt += c;
                if(cnt >= k)
                        return true;
                i ++;
                if(a[i] < x) break;
        }
       // cout <<"cnt :: "<<cnt<<endl;
        if(cnt >= k ) return true;
        return false;
}
int cmp(int a,int b) {
        return a >b;
}
int main(){
        int l,r = 0;
        scanf("%d %d",&n,&k);
        for(int i = 0 ; i < n ; i ++) {
                scanf("%d",&a[i]);
                r = max(r,a[i]);
        }
        sort(a,a+n,cmp);
      //  for(int i = 0 ; i < n ; i ++) printf("%d\n",a[i]);
        l = 1;
        while(l < r) {
                int m = (l+r+1) >> 1;
              //  cout << l<<"   "<<r<<endl;
                if(judge(m)) {
                        l = m;
                }
                else r = m -1;
        }
        int ans = inf;
        if(judge(l)) {
                for(int i = 0 ; i < n ; i ++) {
                        int tmp = a[i];
                        while(tmp >= l) {
                                ans = min(ans,tmp);
                                tmp /= 2;
                        }
                }
                printf("%d\n",ans);
        }
        else puts("-1");

}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <iomanip>          //cout <<fixed<<setprecision(4) <<ans <<endl;
using namespace std;

const int M = 1000000000 +7;
typedef long long ll;
typedef unsigned long long ull;
#define  mem(a) memset(a,0,sizeof a)
#define pi acos(-1.0)
#define inf 0x3f3f3f3f //1.7e9
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const double eps = 1e-10;
const int maxn = 1e6 +5;
int a[maxn],n,k;
int cnt ;
bool judge(int x ) {
        cnt = 0;
        int i = 0;
        while(i < n && a[i] >= x) {
                int base = 1;
                while(a[i] / base >= x) base <<= 1;
                cnt += base / 2 ;
                if(cnt >= k)
                        return true;
                i++;
        }
        if(cnt >= k ) return true;
        return false;
}
int cmp(int a,int b) {
        return a >b;
}
int main(){
        int l = 1,r ;
        scanf("%d %d",&n,&k);
        for(int i = 0 ; i < n ; i ++) {
                scanf("%d",&a[i]);
        }
        sort(a,a+n,cmp);
        int ans = inf;
        if(k <= n) {
                ans = a[k-1];
                l = ans;
        }
        r = a[0];
        while(l < r) {
                int m = (l+r+1) >> 1;
                if(judge(m)) {
                        l = m;
                }
                else r = m -1;
        }

        if(judge(l)) {
                cnt = 0;
                for(int i = 0 ; i < n ; i ++) {
                        int cnt1 = 1;
                        int tmp = a[i];
                        while(tmp >= l) {
                                ans = min(ans,tmp);
                                tmp /= 2;
                                cnt1 >>= 1;
                                if(cnt + cnt1/2 >= k) break;
                        }
                        cnt += cnt1/2;
                }
        }
        if(ans != inf) printf("%d\n",ans);
        else puts("-1");
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <iomanip>          //cout <<fixed<<setprecision(4) <<ans <<endl;
using namespace std;

const int M = 1000000000 +7;
typedef long long ll;
typedef unsigned long long ull;
#define  mem(a) memset(a,0,sizeof a)
#define pi acos(-1.0)
#define inf 0x3f3f3f3f //1.7e9
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const double eps = 1e-10;
const int maxn = 1e6 +5;
int a[maxn],n,k;
int cnt ;
int dp[maxn][20];
bool judge(int x ) {
        cnt = 0;
        int i = 0;
        while(i < n && a[i] >= x) {
                int j = 0;
                int tmp = a[i];
                while(tmp >= x) {
                        tmp /= 2;
                        j ++;
                }
                if(j)  cnt += dp[i][j-1];
                if(cnt >= k)
                        return true;
        }
        if(cnt >= k ) return true;
        return false;
}
int cmp(int a,int b) {
        return a >b;
}
int main(){
        int l = 1,r = 10000;
        scanf("%d %d",&n,&k);
        for(int i = 0 ; i < n ; i ++) {
                scanf("%d",&a[i]);
        }
        sort(a,a+n,cmp);
        for(int i = 0 ; i < n ; i ++) {
                int j = 0;
                dp[i][j] = a[i];
                while(dp[i][j]) {
                        dp[i][j+1] = dp[i][j]/2;
                        j++;
                }
        }
        int ans = inf;
        if(k <= n) {
                ans = a[k-1];
                l = ans;
        }
        while(l < r) {
                int m = (l+r+1) >> 1;
                if(judge(m)) {
                        l = m;
                }
                else r = m -1;
        }

        if(judge(l)) {
                for(int i = 0 ; i < n ; i ++) {
                        int tmp = a[i];
                        while(tmp >= l) {
                                ans = min(ans,tmp);
                                tmp /= 2;
                        }
                }
        }
        if(ans != inf) printf("%d\n",ans);
        else puts("-1");
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <iomanip>          //cout <<fixed<<setprecision(4) <<ans <<endl;
using namespace std;

const int M = 1000000000 +7;
typedef long long ll;
typedef unsigned long long ull;
#define  mem(a) memset(a,0,sizeof a)
#define pi acos(-1.0)
#define inf 0x3f3f3f3f //1.7e9
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const double eps = 1e-10;
const int maxn = 1e6 +5;
int a[maxn],n; ll k;
ll f[maxn*10];
ll getsum(int x,int low) {
        if(x < low) return 0;
        else if(x < 2*low) return 1;
        else return getsum(x/2,low) + getsum(x- x/2,low);
}
bool judge(int x ) {
        ll cnt = 0;
        int i = 0;
        while(i < n && a[i] >= x) {
                cnt += getsum(a[i++],x);
                if(cnt >= k)
                        return true;
                i++;
        }
        if(cnt >= k ) return true;
        return false;
}
int cmp(int a,int b) {
        return a >b;
}
int main(){
        int l = 1,r ;
        scanf("%d %I64d",&n,&k);
        for(int i = 0 ; i < n ; i ++) {
                scanf("%d",&a[i]);
        }
        sort(a,a+n,cmp);
        r = a[0];
        int ans = -1;
        while(l <= r) {
              //  cout <<l<<"   "<<r <<endl;
                int m = (l+r+1) >> 1;
                mem(f);
                ll q = 1;
                for(int i = m ; i <= a[0] ; i ++)
                        f[i] = max(q , f[i/2] + f[i-i/2] );
                ll cnt = 0;
                for(int i = 0 ; i < n ; i ++)
                        cnt += f[a[i]];

                if(cnt >= k)  l = m,ans = m;
                else r = m -1;
                if(l == r) break;
        }
          printf("%d\n",ans);
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <iomanip>          //cout <<fixed<<setprecision(4) <<ans <<endl;
using namespace std;

const int M = 1000000000 +7;
typedef long long ll;
typedef unsigned long long ull;
#define  mem(a) memset(a,0,sizeof a)
#define pi acos(-1.0)
#define inf 0x3f3f3f3f //1.7e9
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const double eps = 1e-10;
const int maxn = 1e6 +5;
int a[maxn],n,k;
int cnt ;
int dp[maxn][20];
bool judge(int x ) {
        cnt = 0;
        int i = 0;
        while(i < n && a[i] >= x) {
                int j = 0;
                int tmp = a[i];
                while(tmp >= x) {
                        tmp /= 2;
                        j ++;
                }
                if(j)  cnt += dp[i][j-1];
                if(cnt >= k)
                        return true;
        }
        if(cnt >= k ) return true;
        return false;
}
int cmp(int a,int b) {
        return a >b;
}
int main(){
        int l = 1,r = 10000;
        scanf("%d %d",&n,&k);
        for(int i = 0 ; i < n ; i ++) {
                scanf("%d",&a[i]);
        }
        sort(a,a+n,cmp);
        mem(dp);
        for(int i = 0 ; i < n ; i ++) {
                int j = 0;
                dp[i][j] = a[i];
                while(dp[i][j]) {
                        dp[i][j+1] = dp[i][j]/2;
                        j++;
                }
        }
        int ans = inf;
        if(k <= n) {
                ans = a[k-1];
                l = ans;
        }
        while(l < r) {
                int m = (l+r+1) >> 1;
                if(judge(m)) {
                        l = m;
                }
                else r = m -1;
        }

        if(judge(l)) {
                for(int i = 0 ; i < n ; i ++) {
                        int tmp = a[i];
                        while(tmp >= l) {
                                ans = min(ans,tmp);
                                tmp /= 2;
                        }
                }
        }
        if(ans != inf) printf("%d\n",ans);
        else puts("-1");
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <iomanip>          //cout <<fixed<<setprecision(4) <<ans <<endl;
using namespace std;

const int M = 1000000000 +7;
typedef long long ll;
typedef unsigned long long ull;
#define  mem(a) memset(a,0,sizeof a)
#define pi acos(-1.0)
#define inf 0x3f3f3f3f //1.7e9
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const double eps = 1e-10;
const int maxn = 1e6 +5;
int a[maxn],n,k;
int cnt ;
bool judge(int x ) {
        cnt = 0;
        int i = 0;
        while(i < n && a[i] >= x) {
                int base = 1;
                while(a[i] / base >= x) base <<= 1;
                cnt += base / 2 ;
                if(cnt >= k)
                        return true;
                i++;
        }
        if(cnt >= k ) return true;
        return false;
}
int cmp(int a,int b) {
        return a >b;
}
int main(){
        int l = 1,r = 10000;
        scanf("%d %d",&n,&k);
        for(int i = 0 ; i < n ; i ++) {
                scanf("%d",&a[i]);
        }
        sort(a,a+n,cmp);
        int ans = inf;
        if(k <= n) {
                ans = a[k-1];
                l = ans;
        }
        while(l < r) {
                int m = (l+r+1) >> 1;
                if(judge(m)) {
                        l = m;
                }
                else r = m -1;
        }

        if(judge(l)) {
                for(int i = 0 ; i < n ; i ++) {
                        int tmp = a[i];
                        while(tmp >= l) {
                                ans = min(ans,tmp);
                                tmp /= 2;
                        }
                }
        }
        if(ans != inf) printf("%d\n",ans);
        else puts("-1");
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <iomanip>          //cout <<fixed<<setprecision(4) <<ans <<endl;
using namespace std;

const int M = 1000000000 +7;
typedef long long ll;
typedef unsigned long long ull;
#define  mem(a) memset(a,0,sizeof a)
#define pi acos(-1.0)
#define inf 0x3f3f3f3f //1.7e9
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const double eps = 1e-10;
const int maxn = 1e6 +5;
int a[maxn],n; ll k;
ll cnt ;
bool judge(int x ) {
        cnt = 0;
        int i = 0;
        while(i < n && a[i] >= x) {
                int base = 1;
                while(a[i] / base >= x) base <<= 1;
                cnt += base / 2 ;
                if(cnt >= k)
                        return true;
                i++;
        }
        if(cnt >= k ) return true;
        return false;
}
int cmp(int a,int b) {
        return a >b;
}
int main(){
        int l = 1,r ;
        scanf("%d %I64d",&n,&k);
        for(int i = 0 ; i < n ; i ++) {
                scanf("%d",&a[i]);
        }
        sort(a,a+n,cmp);
        int ans = inf;
        r = a[0];
        while(l < r) {
                int m = (l+r+1) >> 1;
                if(judge(m)) {
                        l = m;
                }
                else r = m -1;
        }

        if(judge(l)) {
                cnt = 0;
                for(int i = 0 ; i < n ; i ++) {
                        int cnt1 = 1;
                        int tmp = a[i];
                        while(tmp >= l) {
                                ans = min(ans,tmp);
                                tmp /= 2;
                                cnt1 >>= 1;
                                if(cnt + cnt1/2 >= k) break;
                        }
                        cnt += cnt1/2;
                }
        }
        if(ans != inf) printf("%d\n",ans);
        else puts("-1");
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <iomanip>          //cout <<fixed<<setprecision(4) <<ans <<endl;
using namespace std;

const int M = 1000000000 +7;
typedef long long ll;
typedef unsigned long long ull;
#define  mem(a) memset(a,0,sizeof a)
#define pi acos(-1.0)
#define inf 0x3f3f3f3f //1.7e9
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const double eps = 1e-10;
const int maxn = 1e6 +5;
int a[maxn],n,k;
int cnt ;
void getsum(int x,int low) {
        if(x < low) return ;
        else if(x >= low && x <2* low) {
                cnt++;
                return ;
        }
        else{
                getsum( x / 2, low) ;
                getsum(x - (x/2),low);
                return ;
        }
        return ;
}
bool judge(int x ) {
        cnt = 0;
        int i = 0;
        while(i < n && a[i] >= x) {
                getsum(a[i++],x);
                if(cnt >= k)
                        return true;
        }
        if(cnt >= k ) return true;
        return false;
}
int cmp(int a,int b) {
        return a >b;
}
int main(){
        int l = 1,r = 10000;
        scanf("%d %d",&n,&k);
        for(int i = 0 ; i < n ; i ++) {
                scanf("%d",&a[i]);
        }
        sort(a,a+n,cmp);
        int ans = inf;
        if(k <= n) {
                ans = a[k-1];
                l = ans;
        }
        while(l < r) {
                int m = (l+r+1) >> 1;
                if(judge(m)) {
                        l = m;
                }
                else r = m -1;
        }

        if(judge(l)) {
                for(int i = 0 ; i < n ; i ++) {
                        int tmp = a[i];
                        while(tmp >= l) {
                                ans = min(ans,tmp);
                                tmp /= 2;
                        }
                }
        }
        if(ans != inf) printf("%d\n",ans);
        else puts("-1");

}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <iomanip>          //cout <<fixed<<setprecision(4) <<ans <<endl;
using namespace std;

const int M = 1000000000 +7;
typedef long long ll;
typedef unsigned long long ull;
#define  mem(a) memset(a,0,sizeof a)
#define pi acos(-1.0)
#define inf 0x3f3f3f3f //1.7e9
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const double eps = 1e-10;
const int maxn = 1e6 +5;
int a[maxn],n,k;
int cnt ;
bool judge(int x ) {
        cnt = 0;
        int i = 0;
        while(i < n && a[i] >= x) {
                int base = 1;
                while(a[i] / base >= x) base <<= 1;
                cnt += base / 2 ;
                if(cnt >= k)
                        return true;
                i++;
        }
        if(cnt >= k ) return true;
        return false;
}
int cmp(int a,int b) {
        return a >b;
}
int main(){
        int l = 1,r ;
        scanf("%d %d",&n,&k);
        for(int i = 0 ; i < n ; i ++) {
                scanf("%d",&a[i]);
        }
        sort(a,a+n,cmp);
        int ans = inf;
        r = a[0];
        while(l < r) {
                int m = (l+r+1) >> 1;
                if(judge(m)) {
                        l = m;
                }
                else r = m -1;
        }

        if(judge(l)) {
                cnt = 0;
                for(int i = 0 ; i < n ; i ++) {
                        int cnt1 = 1;
                        int tmp = a[i];
                        while(tmp >= l) {
                                ans = min(ans,tmp);
                                tmp /= 2;
                                cnt1 >>= 1;
                                if(cnt + cnt1/2 >= k) break;
                        }
                        cnt += cnt1/2;
                }
        }
        if(ans != inf) printf("%d\n",ans);
        else puts("-1");
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <cmath>
#include <cstdlib>
#include <set>
#include <iomanip>          //cout <<fixed<<setprecision(4) <<ans <<endl;
using namespace std;

const int M = 1000000000 +7;
typedef long long ll;
typedef unsigned long long ull;
#define  mem(a) memset(a,0,sizeof a)
#define pi acos(-1.0)
#define inf 0x3f3f3f3f //1.7e9
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const double eps = 1e-10;
const int maxn = 1e6 +5;
int a[maxn],n,k;
int cnt ;
bool judge(int x ) {
        cnt = 0;
        int i = 0;
        while(i < n && a[i] >= x) {
                int base = 1;
                while(a[i] / base >= x) base <<= 1;
                cnt += base / 2 ;
                if(cnt >= k)
                        return true;
                i++;
        }
        if(cnt >= k ) return true;
        return false;
}
int cmp(int a,int b) {
        return a >b;
}
int main(){
        int l = 1,r = 10000;
        scanf("%d %d",&n,&k);
        for(int i = 0 ; i < n ; i ++) {
                scanf("%d",&a[i]);
        }
        sort(a,a+n,cmp);
        int ans = inf;
        if(k <= n) {
                ans = a[k-1];
                l = ans;
        }
        while(l < r) {
                int m = (l+r+1) >> 1;
                if(judge(m)) {
                        l = m;
                }
                else r = m -1;
        }

        if(judge(l)) {
                cnt = 0;
                for(int i = 0 ; i < n ; i ++) {
                        int cnt1 = 1;
                        int tmp = a[i];
                        while(tmp >= l) {
                                ans = min(ans,tmp);
                                tmp /= 2;
                                cnt1 >>= 1;
                                if(cnt + cnt1/2 >= k) break;
                        }
                        cnt += cnt1/2;
                }
        }
        if(ans != inf) printf("%d\n",ans);
        else puts("-1");
}


#include <bits/stdc++.h>
using namespace std;
int n,k;
int a[1000005];

int get(int num,int mid){

	if(num<mid) return 0;
	if(mid==1) return num;

	int ans=0;

	int ex=log2(num/mid);
	int p=pow(2,ex);
	int q=pow(2,ex+1);

	int num1=num/p;
	int cnt1=p;
	int num2=num1+1;
	int cnt2=num-(p*num1);

	if(mid<=num1){
		ans=max(ans,cnt1);
	}
	if(mid==num2){
		ans=max(ans,cnt2);
	}

	num1=num/q;
	cnt1=q;
	num2=num1+1;
	cnt2=num-(q*num1);

	if(mid<=num1){
		ans=max(ans,cnt1);
	}
	if(mid==num2){
		ans=max(ans,cnt2);
	}

	return ans;

}

bool possible(int mid){
	int cnt=0;
	for(int i=0;i<n;i++){
		cnt+=(get(a[i],mid));
	//	cout<<cnt<<" "<<mid<<endl;
	}

	if(cnt>=k){ return true;}
	//cout<<mid<<endl;
	return false;

}

int main(){
	cin>>n>>k;
	int s=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		s+=(a[i]);
	}
	int maxa=s/k;
	int mina=1;

	while(abs(mina-maxa)>1){
		int mid=(mina+maxa)/2;
		if(possible(mid)==true){
			mina=mid;
		}
		else maxa=mid;
	}

	if(possible(maxa)==1) cout<<maxa<<endl;
	else if(possible(mina)==1) cout<<mina<<endl;
	else cout<<-1<<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define maxn 1000005
#define INF 1000000000

long long n,k;
long long a[maxn];

bool possible(long long mid){
	long long cnt=0;
	for(long long i=0;i<n;i++){
		cnt+=(a[i]/mid);
	}
	if(cnt>=k){
		return true;
	}
	return false;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>k;
	long long mina=INF;
	long long s=0;
	for(long long i=0;i<n;i++){
		cin>>a[i];
		mina=min(mina,a[i]);
		s+=(a[i]);
	}

	long long maxa=s/k;
	mina=1;

	if(maxa==0){
		cout<<-1<<endl;
		return 0;
	}

	while(abs(mina-maxa)>1){
		long long mid=(mina+maxa)/2;

		if(mid==0){
			mina=mid+1;
			continue;
		}

		if(maxa==0){
			cout<<-1<<endl;
			return 0;
		}

		if(possible(mid)==1){
			mina=mid;
		}
		else maxa=mid;
		//cout<<mina<<" "<<maxa<<endl;
	}

	if(possible(maxa)==1)cout<<maxa<<endl;
	else if(possible(mina)==1) cout<<mina<<endl;
	else cout<<-1<<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long n,k;
long long a[1000005];

long long max(long long x,long long y){
	if(x<y) return y;
	else return x;
}

long long get(long long num,long long mid){

	if(num<mid) return 0;
	if(mid==1) return num;

	long long ans=0;

	long long ex=log2(num/mid);
	long long p=pow(2,ex);
	long long q=pow(2,ex+1);

	long long num1=num/p;
	long long cnt1=p;
	long long num2=num1+1;
	long long cnt2=num-(p*num1);

	if(mid<=num1){
		ans=max(ans,cnt1);
	}
	if(mid==num2){
		ans=max(ans,cnt2);
	}

	num1=num/q;
	cnt1=q;
	num2=num1+1;
	cnt2=num-(q*num1);

	if(mid<=num1){
		ans=max(ans,cnt1);
	}
	if(mid==num2){
		ans=max(ans,cnt2);
	}

	return ans;

}

bool possible(long long mid){
	long long cnt=0,x;
	for(long long i=0;i<n;i++){
		if(i>=1) if(a[i]==a[i-1]){
			cnt+=x;
			continue;
		}
		x=(get(a[i],mid));
		cnt+=x;
	//	cout<<cnt<<" "<<mid<<endl;
	}

	if(cnt>=k){ return true;}
	//cout<<mid<<endl;
	return false;

}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>k;
	long long s=0;
	for(long long i=0;i<n;i++){
		cin>>a[i];
		s+=(a[i]);
	}
	sort(a,a+n);
	long long maxa=s/k;
	long long mina=1;

	if(maxa==0){
		cout<<-1<<endl;
		return 0;
	}

	while(abs(mina-maxa)>1){
		long long mid=(mina+maxa)/2;
		if(possible(mid)==true){
			mina=mid;
		}
		else maxa=mid;
	}

	if(possible(maxa)==1) cout<<maxa<<endl;
	else if(possible(mina)==1) cout<<mina<<endl;
	else cout<<-1<<endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long i64;

i64 a[150000];
i64 b[150000];

int main() {
    i64 n; cin >> n;
    for (i64 i = 0; i < n; i++) {
        cin >> b[i];
    }

    i64 ind = 0;
    i64 hi = b[0];
    i64 lo = b[0];
    for (i64 i = 0; i < n; i++) {
        if (b[i] > hi) {
            ind = i;
        }

        hi = max(hi, b[i]);
        lo = min(lo, b[i]);
    }

    if (ind == 0) {
        for (i64 i = n-1; i > 0; i--) {
            if (b[i] != hi) {
                ind = (i+1) % n;
                break;
            }
        }
    }

    if (hi - lo == 0) {
        if (b[0] != 0) {
            cout << "NO" << endl;
        } else {
            cout << "YES" << endl;
            for (i64 i = 0; i < n; i++) {
                cout << "7 ";
            } cout << endl;
        }
        return 0;
    }
    cout << "YES" << endl;
    a[ind] = b[ind];

    for (i64 i = 1LL; i < n; i++) {
        i64 p = (ind - i + n) % n;
        a[p] = b[p] + a[(p+1) % n];
    }

    // add stupid multiple at the end
    for (i64 i = 0; i < n; i++) {
        if (i == ind) continue;
        a[i] += b[ind] * 2;
    }

    for (i64 i = 0; i < n; i++) {
        cout << a[i] << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long i64;

i64 a[150000];
i64 b[150000];

int main() {
    i64 n; cin >> n;
    for (i64 i = 0; i < n; i++) {
        cin >> b[i];
    }

    i64 ind = 0;
    i64 hi = b[0];
    i64 lo = b[0];
    for (i64 i = 0; i < n; i++) {
        if (b[i] > hi) {
            ind = i;
        }

        hi = max(hi, b[i]);
        lo = min(lo, b[i]);
    }

    if (hi - lo == 0 && b[0] != 0) {
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    a[ind] = b[ind];

    for (i64 i = 1; i < n; i++) {
        i64 p = (ind - i + n) % n;
        a[p] = b[p] + a[(p+1) % n];
    }

    // add stupid multiple at the end
    for (i64 i = 0; i < n; i++) {
        if (i == ind) continue;
        a[i] += b[ind] * 2;
    }

    for (i64 i = 0; i < n; i++) {
        cout << a[i] << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long i64;

i64 a[100000];
i64 b[100000];

int main() {
    i64 n; cin >> n;
    for (i64 i = 0; i < n; i++) {
        cin >> b[i];
    }

    i64 ind = 0;
    i64 hi = b[0];
    i64 lo = b[0];
    for (i64 i = 0; i < n; i++) {
        if (b[i] > hi) {
            ind = i;
        }

        hi = max(hi, b[i]);
        lo = min(lo, b[i]);
    }

    if (hi - lo == 0) {
        if (b[0] != 0) {
            cout << "NO" << endl;
        } else {
            cout << "YES" << endl;
            for (int i = 0; i < n; i++) {
                cout << "7 ";
            } cout << endl;
        }
        return 0;
    }
    cout << "YES" << endl;
    a[ind] = b[ind];

    for (i64 i = 1; i < n; i++) {
        i64 p = (ind - i + n) % n;
        a[p] = b[p] + a[(p+1) % n];
    }

    // add stupid multiple at the end
    for (i64 i = 0; i < n; i++) {
        if (i == ind) continue;
        a[i] += b[ind] * 2;
    }

    for (i64 i = 0; i < n; i++) {
        cout << a[i] << " ";
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
int n,mx,mxx,i,a[200005];
long long ans[200005];
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(mx<a[i])
		{
			mx=a[i];
			mxx=i;
		}
	}
	for(i=1;i<=n;i++)
		if(a[i]!=a[1])
			break;
	if(i>n)
		if(a[1]==0)
		{
			printf("YES\n");
			for(i=1;i<=n;i++)
				printf("1 ");
			return 0;
		}
		else
		{
			printf("NO");
			return 0;
		}
	printf("YES\n");
	ans[mxx]=a[mxx];
	for(i=mxx-1;i>=1;i--)
		ans[i]=ans[i+1]+a[i];
	ans[n+1]=ans[1];
	for(i=n;i>mxx;i--)
		ans[i]=ans[i+1]+a[i];
	if(ans[mxx%n+1]==a[mxx])
		for(i=1;i<=n;i++)
			if(i!=mxx)
				ans[i]*=2;
	for(i=1;i<=n;i++)
		printf("%I64d ",ans[i]);
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
int n,mx,mxx,i,a[200005];
long long ans[200005];
bool flag=true;
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=1;i<=n;i++)
		if(mx<a[i]&&a[i]!=a[(i+n-2)%n+1])
		{
			mx=a[i];
			mxx=i;
		}
	for(i=1;i<=n;i++)
		if(a[i]!=a[1])
			break;
	if(i>n)
		if(a[1]==0)
		{
			printf("YES\n");
			for(i=1;i<=n;i++)
				printf("1 ");
			return 0;
		}
		else
		{
			printf("NO");
			return 0;
		}
	printf("YES\n");
	ans[mxx]=a[mxx];
	for(i=mxx-1;i>=1;i--)
	{
		ans[i]=ans[i+1]+a[i];
		if(a[i]==0&&flag)
		{
			ans[i]*=2;
			flag=false;
		}
	}
	ans[n+1]=ans[1];
	for(i=n;i>mxx;i--)
	{
		ans[i]=ans[i+1]+a[i];
		if(a[i]==0&&flag)
		{
			ans[i]*=2;
			flag=false;
		}
	}
	for(i=1;i<=n;i++)
		printf("%I64d ",ans[i]);
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
int n,mx,mxx,i,a[200005];
long long ans[200005];
bool flag=true;
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=1;i<=n;i++)
		if(mx<a[i]&&a[i]!=a[i%n+1])
		{
			mx=a[i];
			mxx=i;
		}
	for(i=1;i<=n;i++)
		if(a[i]!=a[1])
			break;
	if(i>n)
		if(a[1]==0)
		{
			printf("YES\n");
			for(i=1;i<=n;i++)
				printf("1 ");
			return 0;
		}
		else
		{
			printf("NO");
			return 0;
		}
	printf("YES\n");
	ans[mxx]=a[mxx];
	for(i=mxx-1;i>=1;i--)
	{
		ans[i]=ans[i+1]+a[i];
		if(a[i]==0&&flag)
		{
			ans[i]*=2;
			flag=false;
		}
	}
	ans[n+1]=ans[1];
	for(i=n;i>mxx;i--)
	{
		ans[i]=ans[i+1]+a[i];
		if(a[i]==0&&flag)
		{
			ans[i]*=2;
			flag=false;
		}
	}
	for(i=1;i<=n;i++)
		printf("%I64d ",ans[i]);
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
int n,mx,mxx,i,a[200005];
long long ans[200005];
bool flag=true;
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(mx<a[i])
		{
			mx=a[i];
			mxx=i;
		}
	}
	for(i=1;i<=n;i++)
		if(a[i]!=a[1])
			break;
	if(i>n)
		if(a[1]==0)
		{
			printf("YES\n");
			for(i=1;i<=n;i++)
				printf("1 ");
			return 0;
		}
		else
		{
			printf("NO");
			return 0;
		}
	printf("YES\n");
	ans[mxx]=a[mxx];
	for(i=mxx-1;i>=1;i--)
	{
		ans[i]=ans[i+1]+a[i];
		if(a[i]==0&&flag)
		{
			ans[i]*=2;
			flag=false;
		}
	}
	ans[n+1]=ans[1];
	for(i=n;i>mxx;i--)
	{
		ans[i]=ans[i+1]+a[i];
		if(a[i]==0&&flag)
		{
			ans[i]*=2;
			flag=false;
		}
	}
	for(i=1;i<=n;i++)
		printf("%I64d ",ans[i]);
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
int n,mx,mxx,i,a[200005];
long long ans[200005];
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(mx<a[i])
		{
			mx=a[i];
			mxx=i;
		}
	}
	for(i=1;i<=n;i++)
		if(a[i]!=a[1])
			break;
	if(i>n)
		if(a[1]==0)
		{
			printf("YES\n");
			for(i=1;i<=n;i++)
				printf("1 ");
			return 0;
		}
		else
		{
			printf("NO");
			return 0;
		}
	printf("YES\n");
	ans[mxx]=a[mxx];
	for(i=mxx-1;i>=1;i--)
		ans[i]=ans[i+1]+a[i];
	ans[n+1]=ans[1];
	for(i=n;i>mxx;i--)
		ans[i]=ans[i+1]+a[i];
	for(i=1;i<=n;i++)
		printf("%I64d ",ans[i]);
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
int n,mx,mxx,i,a[200005];
long long ans[200005];
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(mx<a[i])
		{
			mx=a[i];
			mxx=i;
		}
	}
	for(i=1;i<=n;i++)
		if(a[i]!=a[1])
			break;
	if(i>n)
	{
		printf("NO");
		return 0;
	}
	printf("YES\n");
	ans[mxx]=a[mxx];
	for(i=mxx-1;i>=1;i--)
		ans[i]=ans[i+1]+a[i];
	ans[n+1]=ans[1];
	for(i=n;i>mxx;i--)
		ans[i]=ans[i+1]+a[i];
	for(i=1;i<=n;i++)
		printf("%I64d ",ans[i]);
}


//touch {a..m}.in; tee {a..m}.cpp < template.cpp
#include <bits/stdc++.h>
using namespace std;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define forn(i,n) forr(i,0,n)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> ii;
#define dforn(i,n) for(int i=n-1; i>=0; i--)
#define dprint(v) cout << #v"=" << v << endl //;)

#define INF (1e18+1)
#define N 400010

ll a[N], b[N], c[N];
ll n,m,k,t,r,aux,rta;
set <ll> s;
string ss;

int main(){
	//~ freopen("e.in", "r", stdin);
	while(cin >> n){
		//~ cin >> m;
		rta = true;
		zero(a);
		forn (i,n) cin >> a[i];
		//~ a[n] = a[0];
		forn (i,n) b[i] = max (a[i], a[(i+n-1)%n]+1);
				//~ forn (i,n) cout << b[i] << (i==n-1?'\n':' ');
				//~ forn (i,n) cout << a[i] << (i==n-1?'\n':' ');

		int auxp = -1;
		//~ aux = b[0];
		forn (i,n) {
			if (a[i] == b[i]){
				auxp = i;
				break;
				//~ aux = b[i];
			}
		}
		if (auxp == -1) rta = false;
		//~ dprint(auxp);
		forn (i,n-1){
			int pos = (auxp-i-1+n)%n;
			int pos1 = (pos + 1) % n;
			//~ b[pos] += b[pos1]+a[pos]-b[pos]%b[pos1];

			//~ b[pos] = max(b[pos1]+a[pos],b[pos]-b[pos]%b[pos1]+a[pos];
			//~ ll aux1 = b[pos1]+a[pos];
			ll aux2 = ((b[pos]%b[pos1]-a[pos])%b[pos1]+b[pos1])%b[pos1];
			b[pos] = b[pos] + aux2;

			//~ dprint(pos);
			//~ dprint(b[pos]);dprint(a[pos]);
		}

		forn (i,n){
			if (b[i]%b[(i+1)%n] != a[i]) rta = false;
			if (b[i] > 1e18) rta = false;
		}

		if (rta){
		cout << "YES" << endl;
		forn (i,n) cout << b[i] << (i==n-1?'\n':' ');}
		else cout << "NO" << endl;
	}
	return 0;
}


//touch {a..m}.in; tee {a..m}.cpp < template.cpp
#include <bits/stdc++.h>
using namespace std;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define forn(i,n) forr(i,0,n)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> ii;
#define dforn(i,n) for(int i=n-1; i>=0; i--)
#define dprint(v) cout << #v"=" << v << endl //;)

#define INF (1e18+1)
#define N 400010

ll a[N], b[N], c[N];
ll n,m,k,t,r,aux,rta;
set <ll> s;
string ss;

int main(){
	//~ freopen("e.in", "r", stdin);
	while(cin >> n){
		//~ cin >> m;
		rta = true;
		zero(a);
		forn (i,n) cin >> a[i];
		//~ a[n] = a[0];

		forn (i,n) b[i] = max (a[i], a[(i+n-1)%n]+1);
				//~ forn (i,n) cout << b[i] << (i==n-1?'\n':' ');
				//~ forn (i,n) cout << a[i] << (i==n-1?'\n':' ');

		int auxp = 0;
		//~ aux = b[0];
		forn (i,n) {
			if (a[i] == b[i]){
				auxp = i;
				break;
				//~ aux = b[i];
			}
		}
		//~ if (auxp == -1) rta = false;
		//~ dprint(auxp);
		forn (i,n-1){
			int pos = (auxp-i-1+n)%n;
			int pos1 = (pos + 1) % n;
			//~ b[pos] += b[pos1]+a[pos]-b[pos]%b[pos1];

			//~ b[pos] = max(b[pos1]+a[pos],b[pos]-b[pos]%b[pos1]+a[pos];
			//~ ll aux1 = b[pos1]+a[pos];
			ll aux2 = ((-b[pos]%b[pos1]+a[pos])%b[pos1]+b[pos1])%b[pos1];
			b[pos] = b[pos] + aux2;

			//~ dprint(pos);
			//~ dprint(b[pos]);dprint(a[pos]);
		}

		forn (i,n){
			if (b[i]%b[(i+1)%n] != a[i]) rta = false;
			if (b[i] > 1e18) rta = false;
		}

		if (rta){
		cout << "YES" << endl;
		forn (i,n) cout << b[i] << (i==n-1?'\n':' ');}
		else cout << "NO" << endl;
	}
	return 0;
}


//touch {a..m}.in; tee {a..m}.cpp < template.cpp
#include <bits/stdc++.h>
using namespace std;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define forn(i,n) forr(i,0,n)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> ii;
#define dforn(i,n) for(int i=n-1; i>=0; i--)
#define dprint(v) cout << #v"=" << v << endl //;)

#define INF (1e18+1)
#define N 400010

ll a[N], b[N], c[N];
ll n,m,k,t,r,aux,rta;
set <ll> s;
string ss;

int main(){
	//~ freopen("e.in", "r", stdin);
	while(cin >> n){
		//~ cin >> m;
		rta = true;
		zero(a);
		forn (i,n) cin >> a[i];
		//~ a[n] = a[0];
		forn (i,n) b[i] = max (a[i], a[(i+n-1)%n]+1);
				//~ forn (i,n) cout << b[i] << (i==n-1?'\n':' ');
				//~ forn (i,n) cout << a[i] << (i==n-1?'\n':' ');

		int auxp = -1;
		//~ aux = b[0];
		forn (i,n) {
			if (a[i] == b[i]){
				auxp = i;
				break;
				//~ aux = b[i];
			}
		}
		if (auxp == -1) rta = false;
		//~ dprint(auxp);
		forn (i,n-1){
			int pos = (auxp-i-1+n)%n;
			int pos1 = (pos + 1) % n;
			b[pos] += b[pos1]+a[pos]-b[pos]%b[pos1];

			//~ b[pos] = max(b[pos1]+a[pos],b[pos]-b[pos]%b[pos1]+a[pos];
			//~ ll aux1 = b[pos1]+a[pos];
			ll aux2 = ((b[pos]%b[pos1]-a[pos])%b[pos1]+b[pos1])%b[pos1];
			b[pos] = b[pos] + aux2;

			//~ dprint(pos);
			//~ dprint(b[pos]);dprint(a[pos]);
		}

		forn (i,n){
			if (b[i]%b[(i+1)%n] != a[i]) rta = false;
			if (b[i] > 1e18) rta = false;
		}

		if (rta){
		cout << "YES" << endl;
		forn (i,n) cout << b[i] << (i==n-1?'\n':' ');}
		else cout << "NO" << endl;
	}
	return 0;
}


//touch {a..m}.in; tee {a..m}.cpp < template.cpp
#include <bits/stdc++.h>
using namespace std;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define forn(i,n) forr(i,0,n)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> ii;
#define dforn(i,n) for(int i=n-1; i>=0; i--)
#define dprint(v) cout << #v"=" << v << endl //;)

#define INF (1e18+1)
#define N 400010

ll a[N], b[N], c[N];
ll n,m,k,t,r,aux,rta;
set <ll> s;
string ss;

int main(){
	//~ freopen("e.in", "r", stdin);
	while(cin >> n){
		//~ cin >> m;
		rta = true;
		zero(a);
		forn (i,n) cin >> a[i];
		//~ a[n] = a[0];
		forn (i,n) b[i] = max (a[i], a[(i+n-1)%n]+1);
				//~ forn (i,n) cout << b[i] << (i==n-1?'\n':' ');
				//~ forn (i,n) cout << a[i] << (i==n-1?'\n':' ');

		int auxp = -1;
		//~ aux = b[0];
		forn (i,n) {
			if (a[i] == b[i]){
				auxp = i;
				break;
				//~ aux = b[i];
			}
		}
		if (auxp == -1) rta = false;
		//~ dprint(auxp);
		forn (i,n-1){
			int pos = (auxp-i-1+n)%n;
			int pos1 = (pos + 1) % n;
			b[pos] += b[pos1]+a[pos]-b[pos]%b[pos1];
			//~ dprint(pos);
			//~ dprint(b[pos]);dprint(a[pos]);
		}

		forn (i,n){
			if (b[i]%b[(i+1)%n] != a[i]) rta = false;
		}

		if (rta){
		cout << "YES" << endl;
		forn (i,n) cout << b[i] << (i==n-1?'\n':' ');}
		else cout << "NO" << endl;
	}
	return 0;
}


//touch {a..m}.in; tee {a..m}.cpp < template.cpp
#include <bits/stdc++.h>
using namespace std;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define forn(i,n) forr(i,0,n)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> ii;
#define dforn(i,n) for(int i=n-1; i>=0; i--)
#define dprint(v) cout << #v"=" << v << endl //;)

#define INF (1e18+1)
#define N 400010

ll a[N], b[N], c[N];
ll n,m,k,t,r,aux,rta;
set <ll> s;
string ss;

int main(){
	//~ freopen("e.in", "r", stdin);
	while(cin >> n){
		//~ cin >> m;
		rta = true;
		zero(a);
		forn (i,n) cin >> a[i];
		//~ a[n] = a[0];
		forn (i,n) b[i] = max (a[i], a[(i+n-1)%n]+1);
				//~ forn (i,n) cout << b[i] << (i==n-1?'\n':' ');
				//~ forn (i,n) cout << a[i] << (i==n-1?'\n':' ');

		int auxp = -1;
		//~ aux = b[0];
		forn (i,n) {
			if (a[i] == b[i]){
				auxp = i;
				break;
				//~ aux = b[i];
			}
		}
		if (auxp == -1) rta = false;
		//~ dprint(auxp);
		forn (i,n-1){
			int pos = (auxp-i-1+n)%n;
			int pos1 = (pos + 1) % n;
			//~ b[pos] += b[pos1]+a[pos]-b[pos]%b[pos1];

			//~ b[pos] = max(b[pos1]+a[pos],b[pos]-b[pos]%b[pos1]+a[pos];
			//~ ll aux1 = b[pos1]+a[pos];
			ll aux2 = ((b[pos]%b[pos1]-a[pos])%b[pos1]+b[pos1])%b[pos1];
			if (aux2 < 0) aux2 = b[pos1] + aux2;
			b[pos] = b[pos] + aux2;

			//~ dprint(pos);
			//~ dprint(b[pos]);dprint(a[pos]);
		}

		forn (i,n){
			if (b[i]%b[(i+1)%n] != a[i]) rta = false;
			//~ if (b[i] > 1e18) rta = false;
		}

		if (rta){
		cout << "YES" << endl;
		forn (i,n) cout << b[i] << (i==n-1?'\n':' ');}
		else cout << "NO" << endl;
	}
	return 0;
}


//touch {a..m}.in; tee {a..m}.cpp < template.cpp
#include <bits/stdc++.h>
using namespace std;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define forn(i,n) forr(i,0,n)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> ii;
#define dforn(i,n) for(int i=n-1; i>=0; i--)
#define dprint(v) cout << #v"=" << v << endl //;)

#define INF (1e18+1)
#define N 400010

ll a[N], b[N], c[N];
ll n,m,k,t,r,aux,rta;
set <ll> s;
string ss;

int main(){
	//~ freopen("e.in", "r", stdin);
	while(cin >> n){
		//~ cin >> m;
		rta = true;
		zero(a);
		forn (i,n) cin >> a[i];
		//~ a[n] = a[0];
		forn (i,n) b[i] = max (a[i], a[(i+n-1)%n]+1);
				//~ forn (i,n) cout << b[i] << (i==n-1?'\n':' ');
				//~ forn (i,n) cout << a[i] << (i==n-1?'\n':' ');

		int auxp = -1;
		//~ aux = b[0];
		forn (i,n) {
			if (a[i] == b[i]){
				auxp = i;
				break;
				//~ aux = b[i];
			}
		}
		if (auxp == -1) rta = false;
		//~ dprint(auxp);
		forn (i,n-1){
			int pos = (auxp-i-1+n)%n;
			int pos1 = (pos + 1) % n;
			//~ b[pos] += b[pos1]+a[pos]-b[pos]%b[pos1];

			//~ b[pos] = max(b[pos1]+a[pos],b[pos]-b[pos]%b[pos1]+a[pos];
			//~ ll aux1 = b[pos1]+a[pos];
			ll aux2 = ((b[pos]%b[pos1]-a[pos])%b[pos1]+b[pos1])%b[pos1];
			if (aux2 < 0) aux2 = b[pos1] + aux2;
			b[pos] = b[pos] + aux2;

			//~ dprint(pos);
			//~ dprint(b[pos]);dprint(a[pos]);
		}

		forn (i,n){
			if (b[i]%b[(i+1)%n] != a[i]) rta = false;
			if (b[i] > 1e18) rta = false;
		}

		if (rta){
		cout << "YES" << endl;
		forn (i,n) cout << b[i] << (i==n-1?'\n':' ');}
		else cout << "NO" << endl;
	}
	return 0;
}


//touch {a..m}.in; tee {a..m}.cpp < template.cpp
#include <bits/stdc++.h>
using namespace std;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define forn(i,n) forr(i,0,n)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> ii;
#define dforn(i,n) for(int i=n-1; i>=0; i--)
#define dprint(v) cout << #v"=" << v << endl //;)

#define INF (1e18+1)
#define N 400010

ll a[N], b[N], c[N];
ll n,m,k,t,r,aux,rta;
set <ll> s;
string ss;

int main(){
	//~ freopen("e.in", "r", stdin);
	while(cin >> n){
		//~ cin >> m;
		rta = true;
		zero(a);
		forn (i,n) cin >> a[i];
		//~ a[n] = a[0];
		forn (i,n) b[i] = max (a[i], a[(i+n-1)%n]+1);
				//~ forn (i,n) cout << b[i] << (i==n-1?'\n':' ');
				//~ forn (i,n) cout << a[i] << (i==n-1?'\n':' ');

		int auxp = -1;
		//~ aux = b[0];
		forn (i,n) {
			if (a[i] == b[i]){
				auxp = i;
				break;
				//~ aux = b[i];
			}
		}
		if (auxp == -1) rta = false;
		//~ dprint(auxp);
		forn (i,n-1){
			int pos = (auxp-i-1+n)%n;
			int pos1 = (pos + 1) % n;
			b[pos] += b[pos1]+a[pos]-b[pos]%b[pos1];

			//~ b[pos] = max(b[pos1]+a[pos],b[pos]-b[pos]%b[pos1]+a[pos];
			//~ ll aux1 = b[pos1]+a[pos];
			ll aux2 = (b[pos]%b[pos1]-a[pos]+b[pos1])%b[pos1];
			b[pos] = b[pos] + aux2;

			//~ dprint(pos);
			//~ dprint(b[pos]);dprint(a[pos]);
		}

		forn (i,n){
			if (b[i]%b[(i+1)%n] != a[i]) rta = false;
			if (b[i] > 1e18) rta = false;
		}

		if (rta){
		cout << "YES" << endl;
		forn (i,n) cout << b[i] << (i==n-1?'\n':' ');}
		else cout << "NO" << endl;
	}
	return 0;
}


//touch {a..m}.in; tee {a..m}.cpp < template.cpp
#include <bits/stdc++.h>
using namespace std;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define forn(i,n) forr(i,0,n)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> ii;
#define dforn(i,n) for(int i=n-1; i>=0; i--)
#define dprint(v) cout << #v"=" << v << endl //;)

#define INF (1e18+1)
#define N 400010

ll a[N], b[N], c[N];
ll n,m,k,t,r,aux,rta;
set <ll> s;
string ss;

int main(){
	//~ freopen("e.in", "r", stdin);
	while(cin >> n){
		//~ cin >> m;
		rta = true;
		zero(a);
		forn (i,n) cin >> a[i];
		//~ a[n] = a[0];
		forn (i,n) b[i] = max (a[i], a[(i+n-1)%n]+1);
				//~ forn (i,n) cout << b[i] << (i==n-1?'\n':' ');
				//~ forn (i,n) cout << a[i] << (i==n-1?'\n':' ');

		int auxp = -1;
		//~ aux = b[0];
		forn (i,n) {
			if (a[i] == b[i]){
				auxp = i;
				break;
				//~ aux = b[i];
			}
		}
		if (auxp == -1) rta = false;
		//~ dprint(auxp);
		forn (i,n-1){
			int pos = (auxp-i-1+n)%n;
			int pos1 = (pos + 1) % n;
			//~ b[pos] += b[pos1]+a[pos]-b[pos]%b[pos1];

			//~ b[pos] = max(b[pos1]+a[pos],b[pos]-b[pos]%b[pos1]+a[pos];
			//~ ll aux1 = b[pos1]+a[pos];
			ll aux2 = ((-b[pos]%b[pos1]+a[pos])%b[pos1]+b[pos1])%b[pos1];
			b[pos] = b[pos] + aux2;

			//~ dprint(pos);
			//~ dprint(b[pos]);dprint(a[pos]);
		}

		forn (i,n){
			if (b[i]%b[(i+1)%n] != a[i]) rta = false;
			if (b[i] > 1e18) rta = false;
		}

		if (rta){
		cout << "YES" << endl;
		forn (i,n) cout << b[i] << (i==n-1?'\n':' ');}
		else cout << "NO" << endl;
	}
	return 0;
}


//touch {a..m}.in; tee {a..m}.cpp < template.cpp
#include <bits/stdc++.h>
using namespace std;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define forn(i,n) forr(i,0,n)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> ii;
#define dforn(i,n) for(int i=n-1; i>=0; i--)
#define dprint(v) cout << #v"=" << v << endl //;)

#define INF (1e18+1)
#define N 400010

ll a[N], b[N], c[N];
ll n,m,k,t,r,aux,rta;
set <ll> s;
string ss;

int main(){
	//~ freopen("e.in", "r", stdin);
	while(cin >> n){
		//~ cin >> m;
		rta = true;
		zero(a);
		forn (i,n) cin >> a[i];
		//~ a[n] = a[0];
		forn (i,n) b[i] = max (a[i], a[(i+n-1)%n]+1);
				//~ forn (i,n) cout << b[i] << (i==n-1?'\n':' ');
				//~ forn (i,n) cout << a[i] << (i==n-1?'\n':' ');

		int auxp = 0;
		//~ aux = b[0];
		forn (i,n) {
			if (a[i] == b[i]){
				auxp = i;
				break;
				//~ aux = b[i];
			}
		}
		//~ if (auxp == -1) rta = false;
		//~ dprint(auxp);
		forn (i,n-1){
			int pos = (auxp-i-1+n)%n;
			int pos1 = (pos + 1) % n;
			b[pos] += b[pos1]+a[pos]-b[pos]%b[pos1];
			//~ dprint(pos);
			//~ dprint(b[pos]);dprint(a[pos]);
		}

		forn (i,n){
			if (b[i]%b[(i+1)%n] != a[i]) rta = false;
		}

		if (rta){
		cout << "YES" << endl;
		forn (i,n) cout << b[i] << (i==n-1?'\n':' ');}
		else cout << "NO" << endl;
	}
	return 0;
}


#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

int N;

int previous(int index) {
    return index == 0 ? N - 1 : index - 1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;
    vector<int> B(N);

    for (int i = 0; i < N; i++)
        cin >> B[i];

    int most = *max_element(B.begin(), B.end());
    int index = -1;

    for (int i = 0; i < N; i++)
        if (B[i] == most && B[previous(i)] != most)
            index = i;

    if (index == -1) {
        cout << "NO" << '\n';
        return 0;
    }

    vector<int> A = B;

    for (int current = index; previous(current) != index; current = previous(current))
        A[previous(current)] += A[current];

    cout << "YES" << '\n';

    for (int i = 0; i < N; i++)
        cout << A[i] << (i < N - 1 ? ' ' : '\n');

    return 0;
}


#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

int N;

int previous(int index) {
    return index == 0 ? N - 1 : index - 1;
}

void answer(const vector<int> &A) {
    cout << "YES" << '\n';

    for (int i = 0; i < N; i++)
        cout << A[i] << (i < N - 1 ? ' ' : '\n');
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;
    vector<int> B(N);

    for (int i = 0; i < N; i++)
        cin >> B[i];

    int most = *max_element(B.begin(), B.end());

    if (most == 0) {
        answer(vector<int>(N, 1));
        return 0;
    }

    int index = -1;

    for (int i = 0; i < N; i++)
        if (B[i] == most && B[previous(i)] < most)
            index = i;

    if (index == -1) {
        cout << "NO" << '\n';
        return 0;
    }

    vector<int> A = B;

    for (int current = index; previous(current) != index; current = previous(current))
        A[previous(current)] += A[current];

    answer(A);
    return 0;
}


#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

int N;

int previous(int index) {
    return index == 0 ? N - 1 : index - 1;
}

void answer(const vector<long long> &A) {
    cout << "YES" << '\n';

    for (int i = 0; i < N; i++)
        cout << A[i] << (i < N - 1 ? ' ' : '\n');
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;
    vector<int> B(N);

    for (int i = 0; i < N; i++)
        cin >> B[i];

    int most = *max_element(B.begin(), B.end());

    if (most == 0) {
        answer(vector<long long>(N, 1));
        return 0;
    }

    int index = -1;

    for (int i = 0; i < N; i++)
        if (B[i] == most && B[previous(i)] < most)
            index = i;

    if (index == -1) {
        cout << "NO" << '\n';
        return 0;
    }

    vector<long long> A(B.begin(), B.end());

    for (int current = index; previous(current) != index; current = previous(current))
        A[previous(current)] += (current == index ? 2 : 1) * A[current];

    answer(A);
    return 0;
}


#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

int N;

int previous(int index) {
    return index == 0 ? N - 1 : index - 1;
}

void answer(const vector<long long> &A) {
    cout << "YES" << '\n';

    for (int i = 0; i < N; i++)
        cout << A[i] << (i < N - 1 ? ' ' : '\n');
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;
    vector<int> B(N);

    for (int i = 0; i < N; i++)
        cin >> B[i];

    int most = *max_element(B.begin(), B.end());

    if (most == 0) {
        answer(vector<long long>(N, 1));
        return 0;
    }

    int index = -1;

    for (int i = 0; i < N; i++)
        if (B[i] == most && B[previous(i)] < most)
            index = i;

    if (index == -1) {
        cout << "NO" << '\n';
        return 0;
    }

    vector<long long> A(B.begin(), B.end());

    for (int current = index; previous(current) != index; current = previous(current))
        A[previous(current)] += A[current];

    answer(A);
    return 0;
}


#include <bits/stdc++.h>
#define int int_fast64_t
using namespace std;
const int MX = 2e5 + 100;
int v[MX], cnt[MX], a[MX], u[MX];
void forward(int n) {
    for(int i = 0; i < n; i ++) {
        if(v[i] and v[i] < v[(i + 1) % n]) {
            u[i] = true;
            a[i] = v[i];
            a[(i + 1) % n] = v[(i + 1) % n];
        }
    }
}
void back(int n) {
    for(int i = n - 1; i >= 0; i --) {
        if(v[i] == 0 and u[(i + 1) % n] and !u[i]) {
            a[i] = a[(i + 1) % n], u[i] = true;
        }
        if(v[i] > 0 and !u[i] and u[(i + 1) % n]) {
            a[i] = v[i];
            a[(i + 1) % n] += ((a[i] - a[(i + 1) % n]) / a[(i + 2) % n] + 1) * a[(i + 2) % n];
            u[i] = true;
        }
    }
}
main () {
    int n; cin >> n;
    int tmp = n;
    int x = -1, y = 1ll << 60;
    for(int i = 0; i < n; i ++) {
        cin >> v[i];
        x = max(x, v[i]);
        y = min(y, v[i]);
    }
    if(x == y and x != 0) return cout << "NO", 0;
    if(x == y and x == 0) {
        cout << "YES\n";
        while(n --) cout << 1 << ' ';
        return 0;
    }
    forward(n);
    back(n);
    back(n);
    cout << "YES\n";
    for(int i = 0; i < n; i ++) {
        cout << a[i] << ' ';
    }
}