#include <iostream>
#include <bitset>
using namespace std;
int v[1000005];
int main(){
    int n, k, i, j, elem, or_sum, and_sum, max_and;
    ios::sync_with_stdio( false );
    cin.tie( 0 );
    cout.tie( 0 );
    cin >> n >> k;
    for( i = 0; i < n; i++ ){
        cin >> v[i];
    }
    max_and = 0;
    for( i = 0; i < ( 1 << n ); i++ ){
        elem = or_sum = 0;
        and_sum = ( 1ll << 31 ) - 1;
        for( j = 0; j < n; j++ ){
            or_sum |= v[j];
            if( ( i & ( 1 << j ) ) != 0 ){
                and_sum &= or_sum;
                or_sum = 0;
                elem++;
            }
        }
        and_sum &= or_sum;
        if( elem == k - 1 ){
            ///cout << ( bitset <20> ) i << ' ' << and_sum << '\n';
            max_and = max( and_sum, max_and );
        }
    }
    cout << max_and;
    return 0;
}
