#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int n=0, k=0, c=0;
int m[1001][1001];

int f(int i=0, int rk=0) {
    if (rk==1) return m[i][n];
    if (n-i==rk) return m[i][i+1]&f(i+1, k-1);
    int maxres=0;
    for (int j=i+1;j<=n-rk+1;j+=1) {
        maxres=max(maxres, m[i][j]&f(j, rk-1));
    }
    return maxres;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin>>n>>k;
    int a[n]{};
    for (int i=0;i<n;i+=1) cin>>a[i];
    for (int i=0;i<n;i+=1) {
        c=a[i];
        for (int j=i+1;j<n;j+=1) {
            m[i][j]=c;
            c=c|a[j];
        }
        m[i][n]=c;
    }
    cout<<f(0, k)<<endl;
    return 0;
}