#include <bits/stdc++.h>

using namespace std;

int n, k;

long long a[1000000];

vector <int> v;

long long answer = 0;

void f1( int i ) {
	
	if ( i == n ) {
		
		if ( (int)v.size() == k - 1 ) {
			
			long long answer1 = 0, j = 0, val = 0;
			
			for ( int i = 0; i < n; i++ ) {
				
				if ( j < k - 1 and v[j] == i ) {
					
					answer1 = ( answer1 & val );
					val = 0;
					j++;
					
				}
				
				val = ( val | a[i] );
				
				if ( j == 0 ) {
					
					answer1 = val;
					
				}
				
				if ( i == n - 1 ) {
					
					answer1 = ( answer1 & val );
					
				}
				
			}
			
			answer = max( answer, answer1 );
			
		}
		
		return;
		
	}
	
	f1( i + 1 );
	if ( i != 0 ) {
		
		v.push_back( i );
		f1( i + 1 );
		v.pop_back();
		
	}
	
	return;
	
}

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;
	
	for ( int i = 0; i < n; i++ ) {
		
		cin >> a[i];
		
		r = ( r | a[i] );
		
	}
	
	if ( n <= 20 ) {
		
		f1( 0 );
		
	} else {
		
		for ( int i = 1; i <= r; i++ ) {
			
			if ( f( i ) == true ) {
				
				answer = i;
				
			}
			
		}
		
	}
	
	cout << answer << endl;
	
	return 0;
	
}