#include <iostream>
#include <fstream>

using namespace std;

const int NMAX = 2000;
using ll = long long;

int v[NMAX + 5];

int main()
{
    ios_base::sync_with_stdio(false);
    ///cin.tie(0);
    ///cout.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    if(n<=20)
    {
        int maxx = 0;
        for(int mask=0;mask<(1<<(n-1));mask++)
        {
            if(__builtin_popcount(mask)!=k-1)
                continue;
            int ans = ~0;
            int curr = v[1];
            for(int i=2;i<=n;i++)
            {
                if((1<<(i-2))&mask)
                {
                    ans = ans & curr;
                    curr = v[i];
                }
                else
                {
                    curr = curr | v[i];
                }
            }
            ans = ans & curr;
            maxx = max(maxx,ans);
        }
        cout<<maxx;
        return 0;
    }

    for(int ans = NMAX;ans>=0;ans--)
    {
        int cnt = 0;
        int i = 1;
        int curr = 0;
        while(i<=n)
        {
            curr = curr | v[i];
            if((curr & ans) == ans)
            {
                cnt++;
                curr = 0;
            }
            i++;
        }
        if(cnt>=k)
        {
            cout<<ans;
            return 0;
        }
    }
    return 0;
}
