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

int check(int md){
    int sum = 0 , co = 0;
    for(int i = 1; i <= n; i++){
        sum |= a[i];
        int ok = 0;
        for(int bit = 0; bit <= 14; bit++){
            if(((sum >> bit) & 1) != ((md >> bit) & 1)){
                ok = 1;
                break;
            }
        }
        if(!ok){
            co++;
            sum = 0;
        }
    }
    if(co >= k){
        return 1;
    }
    return 0;
}

void solve(){
    // jogaba binary search etmeli for 100 point
    cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    int l = 1 , r = 1e9 , ans = 0;
    while(l <= r){
        int md = (l + r) / 2;
        if(check(md)){
            l = md + 1;
            ans = md;
        }
        else{
            r = md - 1;
        }
    }
    cout << ans << endl;
}

int main(){
    solve();
}