#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int n, k;
	cin >> n >> k;
	vector <uint64_t> nums(n);
	uint64_t maxus = 0;
	for (int64_t i = 0; i < n; i++)
	{
		cin >> nums[i];
		maxus = maxus | nums[i];
	}
	
	for (int64_t i = maxus; i >= 0; i--)	
	{
		int kk = k;
		int tec = 0;
		for (auto ii : nums)
		{
			tec |= ii;
			if ((tec & i) == i)
			{
				tec = 0;
				kk--;
			}

		}
		if (kk <= 0) {
			cout << i;
			return 0;
		}
	}
	cout << 0;


	return 0;
}
