#define SENT
#include <iostream>
#include <vector>
#include <stdint.h>
#define int long long

struct SegmentTree {
    std::vector<int> v;
    int n;
};

void segment_tree_build(SegmentTree *t,int node,int st,int dr,std::vector<int> v) {
    if (st == dr) {
        t->v[node] = v[st];
        return;
    }
    int mid = (st + dr)/2;
    segment_tree_build(t,node*2,st,mid,v);
    segment_tree_build(t,node*2+1,mid+1,dr,v);
    t->v[node] = (t->v[node*2] | t->v[node*2+1]);
}

int segment_tree_get(SegmentTree *t,int node,int st,int dr,int l,int r) {
    if (dr < l || st > r) return 0;
    if (l <= st && dr <= r) {
        return t->v[node];
    }
    int mid = (st+dr)/2;
    return (segment_tree_get(t,node*2,st,mid,l,r) | segment_tree_get(t,node*2+1,mid+1,dr,l,r));
}

void init_env() {
    #ifndef SENT
        freopen(RESOURCE_PATH "test.in","r",stdin);
        freopen(RESOURCE_PATH "test.out","w",stdout);
    #endif

    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);
}

int main() {
    init_env();

    int n,k;
    std::cin>>n>>k;

    std::vector<int> v(n+1);
    for (int i=1; i<=n; i++) {
        std::cin>>v[i];
    }

    std::vector<std::vector<int> > dp(n+1,std::vector<int>(k+1,-1));
    // dp[i][j] = folosind primele i posizti si avand j cutturi care e and-ul maxim

    int or1 = 0;
    for (int i=1; i<=n; i++) {
        or1 |= v[i];
        dp[i][1] = or1;
        for (int p=2; p<=k; p++) {
            int sumor = v[i];

            for (int j=i-1; j>0; j--) {
                if (dp[j][p-1] == -1) break;
                dp[i][p] = std::max(dp[i][p],(dp[j][p-1] & sumor));
                sumor |= v[j];
            }

            //std::cout<<dp[i][p]<<" ";
        }
        //std::cout<<"\n";
    }

    std::cout<<dp[n][k];
}

/**
 * 
 * 
 * 
 */