#include <bits/stdc++.h>
using namespace std;

int n , k ;
vector < int > v ;

int a[105] ;

int mx = 0 ;

void correct ()
{
    int st = 1 ;
    int ind = 0 ;
    int idfk = v.size() - 1 ;
    int nr = 0 , sum = -1 ;
    while ( ind <= idfk )
    {
        if ( st == v[ind] )
        {
            nr |= a[st] ;
            if ( sum != -1 )
                sum &= nr ;
            else
                sum = nr ;
            nr = 0 ;
            ind ++ ;
        }
        else
            nr |= a[st] ;
        st ++ ;
    }
    while ( st <= n )
    {
        nr |= a[st] ;
        st ++ ;
    }
    sum &= nr ;
    mx = max ( mx , sum ) ;
}

void permut ( int last_ind , int nr )
{
    if ( nr == k - 1 )
        correct () ;
    else
    {
        for ( int i = last_ind + 1 ; i <= n ; i ++ )
        {
            v.push_back(i) ;
            permut ( i , nr + 1 ) ;
            v.pop_back() ;
        }
    }
}


int main()
{
    std :: cin >> n >> k ;
    for ( int i = 1 ; i <= n ; i ++ )
        std :: cin >> a[i] ;
    permut ( 0 , 0 ) ;
    std :: cout << mx ;

    return 0;
}
