#include <iostream>
///#include <fstream>
using namespace std;
///ifstream cin("eagers.in");
///ofstream cout("eagers.out");
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]=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 ){
                rez=nr[1];
                for( i = 2; i <= k1; i++ )
                    rez=(rez&nr[i]);
                maxi=max(maxi,rez);
            }
        }
        cout<<maxi;
    }
    else{
        int st=1, dr=1000000000, 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( nr[k1] >= mijl )
                    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] >= mijl ){
                rez=nr[1];
                for( i = 2; i <= k1; i++ )
                    rez=(rez&nr[i]);
                st=mijl+1;
                sol=rez;
            }
            else
                dr=mijl-1;
        }
        cout<<sol;
    }
    return 0;
}