#include<bits/stdc++.h>
using namespace std;
#define N 29
int b[N];
int n , k;
vector<int> v;
int mx = 0;
int a[N];

void f(int idx){
    if(idx == n + 1){
        int cnt = 0 , sum = 1;
        for(int i = 1; i <= n; i++){
            if(cnt == k - 1){
                int co = a[min(i + 1 , n)];
                for(int j = i + 2; j <= n; j++){
                    co ^= a[j];
                }
                v.push_back(co);
                int ans = v[0];
                for(int j = 1; j < (int)v.size(); j++){
                    ans &= v[j];
                }
                mx = max(mx , ans);
                // for(auto it : v){
                //     cout << it << " ";
                // }
                // cout << endl;
                v.clear();
                return;
            }
            if(b[i]){
                cnt++;
                sum ^= a[i];
                v.push_back(sum);
                sum = 1;
            }
            else{
                sum ^= a[i];
            }
        }
        return;
    }
    b[idx] = 1;
    f(idx + 1);
    b[idx] = 0;
    f(idx + 1);
}

void solve(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    f(1);
    cout << mx << endl;
}

int main(){
    solve();
}