#include <iostream>
using namespace std;

int n, k;

const int NMAX = 1e6;

int arr[NMAX + 1];

int prevMask = 0;

int main() {
	cin >> n >> k;

	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
	}
	for (int bit = 30; bit >= 0; bit--) {
		int leftMask = prevMask;
		bool foundBit = false;
		int groupCnt = 0;
		for (int i = 1; i <= n; i++) {
			int overlap = leftMask & arr[i];
			leftMask -= overlap;
			foundBit = foundBit || (arr[i] & (1 << bit)) != 0;
			if (leftMask == 0 && foundBit) {
				foundBit = false;
				leftMask = prevMask;
				groupCnt++;
			}
		}
		if (groupCnt >= k) {
			prevMask = prevMask | (1 << bit);
		}
	}
	cout << prevMask;
	return 0;
}
