#include <iostream>
///#include <fstream>
using namespace std;
///ifstream cin("eagers.in");
///ofstream cout("eagers.out");
bool inclus( int val1, int val2 ){  ///daca val1 include sau nu val2
    if( val1 < val2 )
        return false;
    int i=0, c1, c2;
    bool ok=true;
    while( ok == true && (1<<i) <= val2 ){
        c1=(val1>>i)&1;
        c2=(val2>>i)&1;
        if( c2 == 1 && c1 == 0 )
            ok=false;]
        i++
    }
    return ok;
}
int v[1000001], nr[1000001];
int main()
{
    ///log(10^9)=30
    ///pot cauta binar valoarea maxima posibila
    ///st=0, dr=29;
    int n, k, i, nrmax=-1;
    cin>>n>>k;
    for( i = 1; i <= n; i++ ){
        cin>>v[i];
        nrmax=max(nrmax,v[i]);
    }
    if( nrmax <= 2 ){
        int val, rez, maxi=0, k1;
        for( val = 1; val <= 3; val++ ){
            k1=1;
            nr[1]=v[1];
            i=2;
            while( i <= n && k1 < k ){
                if( nr[k1] >= val && ( nr[k1] != 2 || val != 1 ) )
                    nr[++k1]=v[i];
                else
                    nr[k1]=(nr[k1]|v[i]);
                i++;
            }
            while( i <= n ){
                nr[k1]=(nr[k1]|v[i]);
                i++;
            }
            if( k == k1 && nr[k1] >= val && ( nr[k1] != 2 || val != 1 ) ){
                rez=nr[1];
                for( i = 2; i <= k1; i++ )
                    rez=(rez&nr[i]);
                maxi=max(maxi,rez);
            }
        }
        cout<<maxi;
    }
    else{
        int st=1, dr=nrmax, sol=0, mijl, k1, rez;
        while( st <= dr ){
            mijl=(st+dr)/2;
            k1=1;
            nr[1]=v[1];
            i=2;
            while( i <= n && k1 < k ){
                if( inclus(nr[1],mijl) == true ){
                    nr[++k1]=v[i];
                }
                else
                    nr[k1]=(nr[k1]|v[i]);
                i++;
            }
            while( i <= n ){
                nr[k1]=(nr[k1]|v[i]);
                i++;
            }
            if( k == k1 && inclus(nr[1],mijl) == true ){
                rez=nr[1];
                for( i = 2; i <= k1; i++ )
                    rez=(rez&nr[i]);
                st=mijl+1;
                sol=max(sol,rez);
            }
            else
                dr=mijl-1;
        }
        cout<<sol;
    }
    return 0;
}