#include <bits/stdc++.h>

using namespace std;
using ll = int;

ll cst = 30;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    bool flag = 1;
    for (ll i = 0; i < n; i++)
    {
        cin >> v[i];
        if (v[i] > 2)
        {
            flag = 0;
        }
    }
    if (flag)
    {
        cst = 4;
    }
    ll ans = 0;
    for (ll bt = cst; bt >= 0; bt--)
    {
        ll cur = ans + (1 << bt);
        ll ind = 0;
        ll alr = 0;
        ll now = 0;
        while (ind != n)
        {
            now |= (v[ind]);
            if ((now | cur) == now)
            {
                alr++;
                now = 0;
            }
            ind++;
        }
        if (alr >= k)
        {
            ans = cur;
        }
    }
    cout << ans;
}
