#include <bits/stdc++.h>

using namespace std;

int n, k;

long long a[1000000];

bool f( long long m ) {
	
	int cnt = 0;
	long long val = 0;
	
	for ( int i = 0; i < n; i++ ) {
		
		val = ( val | a[i] );
		
		if ( ( val & m ) == m ) {
			
			cnt++;
			
			val = 0;
			
		}
		
	}
	
	if ( cnt >= k ) {
		
		return true;
		
	}
	
	return false;
	
}

int main() {
	
	ios::sync_with_stdio(0), cin.tie(0);
	
	cin >> n >> k;
	
	long long l = 1, r = 0, m;

	long long answer = 0;
	
	for ( int i = 0; i < n; i++ ) {
		
		cin >> a[i];
		
		r = ( r | a[i] );
		
	}
	
	while ( l <= r ) {
		
		m = l;
		
		if ( f( m ) == true ) {
			
			answer = m;
			
		}
		
		l++;
		
	}
	
	cout << answer << endl;
	
	return 0;
	
}