#include <bits/stdc++.h>

using namespace std;

const int MAXN = 20;
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 );

    cin >> n >> k;
    for ( i = 0 ; i < n ; i++ )
        cin >> a[i];
    bkt ( 1 , 0 );
    cout << maxa << '\n';

    return 0;
}
