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

int n=0, k=0, c=0;
int m[2001][2001];
int dp[2001][2001];

int f(int i=0, int rk=0) {
    if (dp[i][rk]!=-1) return dp[i][rk];
    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 dp[i][rk]=maxres;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin>>n>>k;
    int a[n]{};
    bool t=1;
    int oc=0;
    for (int i=0;i<n;i+=1) {
        cin>>a[i];
        if (a[i]==1) oc+=1;
        if (a[i]>1) t=0;
    }
    if (t) {
        cout<<bool(oc>=k)<<endl;
        return 0;
    }
    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];
            //cout<<m[i][j]<<" ";
        }
        m[i][n]=c;
        //cout<<m[i][n]<<endl;
    }
    for (int i=0;i<=n;i+=1) {
        for (int j=0;j<=n;j+=1) dp[i][j]=-1;
    }
    cout<<f(0, k)<<endl;
    return 0;
}