#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e6 , MAXLG = 29;
int u[MAXLG + 1][MAXN + 1] , a[MAXN];
int n;
bool cond ( int b , int idx ) {
    int l , mx;

    mx = -1;
    for ( l = 0 ; l <= MAXLG ; l++ )
        if ( ( ( 1 << l ) & b ) == ( 1 << l ) )
            mx = max ( mx , u[l][idx] );

    if ( mx < n )
        return 1;
    return 0;
}
int urm ( int b , int idx ) {
    int l , mx;

    mx = -1;
    for ( l = 0 ; l <= MAXLG ; l++ )
        if ( ( ( 1 << l ) & b ) == ( 1 << l ) )
            mx = max ( mx , u[l][idx] );

    return mx + 1;
}
int main () {
    ios_base :: sync_with_stdio ( 0 );
    cin.tie ( 0 );
    int k , i , j , gr;

    cin >> n >> k;
    for ( i = 0 ; i < n ; i++ )
        cin >> a[i];
    for ( i = 0 ; i <= MAXLG ; i++ )
        u[i][n] = n;
    for ( i = n - 1 ; i >= 0 ; i-- ) {
        for ( j = 0 ; j <= MAXLG ; j++ ) {
            if ( ( ( 1 << j ) & a[i] ) == ( 1 << j ) )
                u[j][i] = i;
            else
                u[j][i] = u[j][i + 1];
        }
    }
    for ( i = ( ( 1 << ( MAXLG + 1 ) ) - 1 ) ; i > 0 ; i-- ) {
        j = gr = 0;
        while ( cond ( i , j ) ) {
            j = urm ( i , j );
            gr++;
        }
        if ( gr >= k ) {
            cout << i << '\n';
            return 0;
        }
    }
    cout << "0\n";
    return 0;
}
