#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <limits>
#include <iterator>

using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	vector<long long> a(N);
	for (auto &x : a) {
		cin >> x;
	}

	vector<long long> b;
	for (int l = 0; l < N; ++l) {
		partial_sum(a.begin() + l, a.end(), back_inserter(b));
	}

	for (int i = 40; i >= 0; --i) {
		vector<long long> t;
		for (auto x : b) {
			if (x & (1LL << i)) {
				t.push_back(x);
			}
		}
		if ((int)t.size() >= K) {
			b = move(t);
		}
	}

	long long ans = -1;
	for (auto x : b) {
		ans &= x;
	}
	cout << ans << endl;
}
