#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll MAX_N = 1e6+1;
ll a[MAX_N];

int main()
{
    for (ll i = 0; i < MAX_N; i++)
    {
        a[i] = 0;
    }
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n,k; cin >> n >> k;
    for (ll i = 1; i <= n; i++) cin >> a[i];

    ll best_mask = 0;
    for (ll i = 1; i >= 0; i--)
    {
        ll new_mask = best_mask | (1LL << i);
        ll mask_now = 0, cnt = 0;
        for (ll j = 1; j <= n; j++)
        {
            mask_now |= a[j];
            if ((mask_now & new_mask) == new_mask) {cnt++; mask_now = 0;}
        }
        if (cnt >= k)
        {
            //cout << best_mask << endl;
            best_mask = new_mask;
            //cout << best_mask << endl;
        }
    }

    cout << best_mask << endl;
}
