#include <bits/stdc++.h>
using namespace std;
const int nmax=1e6;
int dp[305][nmax+2];
int v[305];
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin>>n>>k;
    for ( int i=1; i<=n; i++ ) cin>>v[i];
    dp[1][1]=v[1];
    for ( int i=2; i<=n; i++ ) dp[i][1]=dp[i-1][1]|v[i];
    for ( int g=2; g<=k; g++ )
    for ( int i=k; i<=n; i++ )
    {
    int o=v[i];
    for ( int j=i-1; j>=g-1; j-- )
    {
    o=v[j];
    dp[i][g]=max(dp[i][j],dp[j][g-1]&o);
    o=v[j];
    }
    }
    cout<<dp[n][k];
    return 0;
}
