#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#include <intrin.h>
#include <cassert>

inline int __builtin_clz(unsigned int x)
{
	unsigned long l = 0;
	if (_BitScanReverse(&l, x))
	{
		return 31 - l;
	}
	return 32;
}
#endif 

const int N = 1e6 + 67;
const int LOG = 31;

int a[N];
int n;

void solve()
{
	int k;
	cin >> n >> k;

	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}

	int ans = 0;
	int mask = 0;

	for (int i = LOG; i >= 0; i--)
	{
		int l = 1, r = 1;
		int new_mask = mask | (1 << i);
		int cnt = 0;
		int val;
		while (r != n + 1)
		{
			val = a[l];
			if (cnt >= k)break;
			while (r <= n && (val & new_mask) != new_mask)
			{
				r++;
				val |= a[r];
			}
			if (r != n + 1)
			{
				cnt++;
				l = r + 1;
				r = l;
			}
			else break;
		}
		if (cnt >= k)
		{
			ans |= (1 << i);
			mask |= (1 << i);
		}
	}
	cout << ans << "\n";

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	return 0;
}