#include <bits/stdc++.h>

using namespace std;
const int nmax = 1e6;
int dp[305][nmax+2];
int v[305];
int main()
{
    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];
    for ( int g = 2 ; g <= k ; ++ g )
    for ( int i = g ; i <= n ; ++ i )
    {
    int o = v[i];
    for ( int j = i - 1 ; j >= g-1 ; -- j ){
    dp[i][g]=max(dp[i][j],dp[j][g-1]&o);
    o|=v[j];
    }
    }
    cout << dp[n][k] + 1 ;
    return 0;
}
