#include <bits/stdc++.h>
using namespace std;

int n, k;
vector<int> vals;

int calc(vector<int> &arr, vector<int> sizes) {
    vals.resize(k);
    vals.clear();
    int j=0, val;

    for (int i=0; i<n; i++) {
        if (sizes[j]==0) {
            j==0 ? val=vals[j] : val&=vals[j];
            //cout << vals[j] << " " << val << '\n';
            j++;
        }
        vals[j]|=arr[i];
        //cout << vals[j] << ": " << arr[i] << '\n';
        sizes[j]--;
    }

    val&=vals[j];

    return val;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int ans=INT_MIN, idx=0;
    cin >> n >> k;

    vector<int> arr(n), subarr_sizes(k, 1);
    subarr_sizes[k-1]=n-(k-1);
   /* for (int i=0; i<k; i++) cout << subarr_sizes[i] << " ";
    cout << '\n';*/

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

    while (subarr_sizes[k-1]>=1){
        ans=max(calc(arr, subarr_sizes), ans);
        //cout << "ans: " << ans << '\n';
        subarr_sizes[idx]++;
        subarr_sizes[k-1]--;
       /* for (int i=0; i<k; i++) cout << subarr_sizes[i] << " ";
        cout << '\n';*/
        if (idx+1<k-1) idx++;
    }

    cout << ans;


    return 0;
}