#include <iostream>
#include <vector>
using namespace std;

int main(void){
    // freopen("input.txt", "r", stdin);
    int n, k;
    cin>>n>>k;

    vector<int> arr(n, 0);
    vector<vector<int>> dp(n, vector<int>(k+1, 0));

    for(int i = 0; i<n; i++) cin>>arr[i];


    dp[0][1] = arr[0];
    for(int i = 1; i<n; i++) dp[i][1] = dp[i-1][1] | arr[i];

    for(int i = 2; i<=k; i++){
        for(int curr = 0; curr<n; curr++){
            int o = arr[curr];
            for(int j = curr-1; j>=0; j--){
                dp[curr][i] = max(dp[curr][i], (o & dp[j][i-1]));
                o = o|arr[j];
            }
        }
    }

    cout<<dp[n-1][k]<<endl;
    return 0;
}