#include <bits/stdc++.h>

using namespace std;

int n, k;

int a[1000000];

bool f( int m ) {
	
	int cnt = 0, 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;
	
	int l = 1, r = 1000000000, m;

	int answer = 0;
	
	for ( int i = 0; i < n; i++ ) {
		
		cin >> a[i];
		
	}
	
	while ( l <= r ) {
		
		m = ( l + r ) / 2;
		
		if ( f( m ) == true ) {
			
			l = m + 1;
			
			answer = m;
			
		} else {
			
			r = m - 1;
			
		}
		
	}
	
	cout << answer << "\n";
	
	return 0;
	
}