#include <bits/stdc++.h>
//#include <ext/rope>

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define last(s) (s)[int((s).size())-1]
#define prelast(s) (s)[int((s).size())-2]
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define elif else if
#define left asdasd
#define next zaza

#define cclear cout<<flush;
#define x0 kerker
#define time chas
#define y0 lolik
#define kchay ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define files freopen("a.in", "r", stdin);freopen("a.out", "w", stdout);
#define ref svyazi
#define int long long
#define ii pair<int, int>
#define ld long double
#define list spisok


using namespace std;
//using namespace __gnu_cxx;

bool cmp(int a,int b){
    return a>b;
}

int n,k,a[1010],sm,ans;
vector<int> all_sm;
main(){
    kchay;
    cin >> n >> k;
    for (int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        sm=0;
        for (int j=i;j<n;j++){
            sm+=a[j];
            all_sm.pb(sm);
        }
    }
    sort(all(all_sm),cmp);
    int bt=1;
    for (int z=0;bt<=all_sm[0];z++){
            int l=0;
            int temp_ans=0;
        for (auto i:all_sm){
            if ((i|bt)==i) {
                l++;
            }
        }
        if (l<k) ans=max(ans,temp_ans);
        else{
            for(auto i:all_sm){
                if (i|bt==i){
                    i-=bt;
                }
            }
        }
        bt*=2;
    }
    sort(all(all_sm),cmp);
    ans=all_sm[0];
    for (int i=0;i<k;i++){
        ans&=all_sm[i];
    }
    cout<<ans;

}
