#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e6;

int v[nmax+2];
int max1 ;
int n , k ;
void backtrack ( int pos , int c , int nr ){

if ( pos == n + 1 ) {
if ( nr ) return ;
max1=max(max1,c);
return;
}
if ( nr == 0 ) return ;
int o = v[pos];
for ( int i = pos ; i <= n  ; ++ i )
    {
    o|=v[i];
    int newc ;
    if ( c == -1 ) newc = o ;
    else newc = (c&o);
    backtrack(i+1,newc,nr-1);
    }
}
signed main()
{
    cin >> n >> k ;
    for ( int i = 1 ; i <= n ; ++ i ) cin >> v[i];
    int c = -1 ;
    backtrack(1,c,k);
    cout << max1;
    return 0;
}

