#include <bits/stdc++.h>

using namespace std;
using ll = long long;

bool cont(ll a, ll b)
{
    for (ll i = 31; i >= 0; i--)
    {
        if (((b >> i) & 1) && !((a >> i) & 1))
        {
            return 0;
        }
    }
    return 1;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    vector<vector<bool>> bts(n, vector<bool>(32, 0));
    for (ll i = 0; i < n; i++)
    {
        cin >> v[i];
        for (ll j = 31; j >= 0; j--)
        {
            if ((v[i] >> j) & 1)
            {
                bts[i][j] = 1;
            }
        }
    }
    ll ans = 0;
    for (ll bt = 31; bt >= 0; bt--)
    {
        ll cur = ans + (1LL << bt);
        ll ind = 0;
        ll alr = 0;
        ll now = 0;
        while (ind != n)
        {
            now |= (v[ind]);
            if (cont(now, cur))
            {
                alr++;
                now = 0;
            }
            ind++;
        }
        if (alr >= k)
        {
            ans = cur;
        }
    }
    cout << ans;
}
