#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

ll solve(ll N, ll K, vector<ll>& As) {
    vector<ll> beauties;
    REP(i, N) {
        ll sum = 0;
        FOR(j, i, N) {
            sum += As[j];
            beauties.pb(sum);
        }
    }

    //for(auto e: beauties) cout << e << " "; cout << endl;

    ll max_b = *max_element(ALL(beauties));
    int digit_num = 0;
    while(max_b > 0) {
        max_b /= 2;
        ++digit_num;
    }

    //cout << "beauties:" << endl;
    //for(auto e: beauties) {
    //    for(int i = digit_num; i >= 0; --i) {
    //        cout << (((1 << i) & e) ? "1" : "0");
    //    }
    //    cout << endl;
    //}
    
    for(int i = digit_num; i >= 0; --i) {
        vector<ll> nxt;
        for(auto e: beauties) {
            if ((1LL << i) & e) {  // (1 << i) とするとWA?
                nxt.pb(e);
            }
        }
        if (SIZE(nxt) >= K) {
            beauties = nxt;
        }
        // cout << "size: " << SIZE(beauties) << endl;
        // cout << "  "; for(auto e: beauties) cout << e << " "; cout << endl;
    }
    ll ans = 0;
    REP(i, K) {
        if (i == 0) ans = beauties[i];
        else ans &= beauties[i];
    }
    return ans;
}

ll slow(ll N, ll K, vector<ll>& As) {
    vector<ll> beauties;
    REP(i, N) {
        ll sum = 0;
        FOR(j, i, N) {
            sum += As[j];
            beauties.pb(sum);
        }
    }

    

    vector<int> shff(SIZE(beauties));
    REP(k, K) shff[k] = 1;
    sort(ALL(shff));
    ll ans = 0;
    do {
        bool first = true;
        ll sum = 0;
        REP(n, SIZE(beauties)) {
            if (shff[n]) {
                if (first) sum = beauties[n];
                else sum &= beauties[n];
				first = false;
            }
        }
        ans = max(ans, sum);
    }while(next_permutation(ALL(shff)));
    return ans;
}

#include <random>
int main(void)
{
    cin.sync_with_stdio(false);
     ll N, K;
     cin >> N >> K;
     vector<ll> As(N);
     REP(n, N) cin >> As[n];
	 cout << solve(N, K, As) << endl;

	return 0;

	// for debug
	std::random_device r;
	std::default_random_engine e1(r());
	std::uniform_int_distribution<int> uniform_dist(1, 1e9);
    while(1) {
		ll N = rand() % 5 + 2;
		ll K = rand() % (N * (N + 1) / 2 - 1) + 1;
        vector<ll> As(N);
		REP(n, N) As[n] = uniform_dist(e1);

        ll ans1 = solve(N, K, As);
        ll ans2 = slow(N, K, As);
        if (ans1 != ans2) {
            cout << "error! ans1, ans2 = " << ans1 << "," << ans2 << endl;
            for(auto a: As) cout << a << " "; cout << endl;
            break;
        }
        
    }

	return 0;



}


Measured memory_bytes: 6384