#include<bits/stdc++.h>

#define FOR(i,b,e) for(int i = b; i <= e; i++)
#define FORD(i,b,e) for(int i = b; i >= e; i--)

using namespace std;

const int maxn = 200042;

typedef long long LL;

LL n, k;

LL masks[maxn];


int main() {
    ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> k;

	FOR(i, 1, n)
	{
		cin >> masks[i];
	}

	LL ans = 0;

	FORD(bit, 30, 0)
	{
		LL ma = (LL(1) << bit);
		int c = 0;
		FOR(i, 1, n)
			if(ma & masks[i])
				c++;
		if(c >= k)
		{
			ans += ma;
			FOR(i, 1, n)
			{
				if(!(ma & masks[i]))
				{
					swap(masks[i], masks[n]);
					n--;
					i--;
				}
			}
		}
	}

	cout << ans << '\n';




}

