#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e6;
int a[MAXN + 1] , sep[MAXN + 1];
int n , k , maxa , i;
void bkt ( int poz , int nrs ) {
    if ( poz == n ) {
        if ( nrs == k - 1 ) {
            int val , ans;
            val = 0;
            ans = ( 1 << 30 ) - 1;
            for ( i = 0 ; i < n ; i++ ) {
                if ( !sep[i] )
                    val |= a[i];
                else {
                    ans &= val;
                    val = a[i];
                }
            }
            maxa = max ( maxa , ans & val );
        }
    } else {
        sep[poz] = 0;
        bkt ( poz + 1 , nrs );
        sep[poz] = 1;
        bkt ( poz + 1 , nrs + 1 );
    }
}
int main () {
    ios_base :: sync_with_stdio ( 0 );
    cin.tie ( 0 );

    int ok = 1;
    cin >> n >> k;
    for ( i = 0 ; i < n ; i++ ) {
        cin >> a[i];
        if ( a[i] >= 2 )
            ok = 0;
    }
    if ( n <= 20 ) {
        bkt ( 1 , 0 );
        cout << maxa << '\n';
        return 0;
    } else if ( ok ) {
        int g = 1;
        for ( i = 0 ; i < n ; i++ )
            if ( a[i] == 1 )
                g++;
        if ( g >= k )
            cout << 1;
        else
            cout << 0;
    } else {
        for ( i = 2047 ; i > 0 ; i-- ) {
            int sau = 0 , j , g = 0;
            for ( j = 0 ; j < n ; j++ ) {
                sau |= a[j];
                if ( ( i & sau ) == i ) {
                    g++;
                    sau = 0;
                }
            }
            if ( g >= k ) {
                cout << i << '\n';
                return 0;
            }
        }
        cout << "0\n";
    }
    return 0;
}
