#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 care bit imi doresc sa il am 1, cat mai indepartat
    ///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 w, k1, maxi=0;
        for( w = 1; w <= 2; w++ ){
            k1=1;
            nr[1]=v[1];
            i=2;
            while( i <= n && k1 < k ){
                if( nr[k1] < w )
                    nr[k1]=nr[k1]|v[i];
                else
                    nr[++k1]=v[i];
                
            }
        }
    }
    */
    int st=0, dr=29, mijl, k1, rez, maxi=0;
    while( st <= dr ){
        mijl=(st+dr)/2; ///bitul mijl
        k1=1;
        nr[1]=v[1];
        i=2;
        while( i <= n && k1 < k ){
            if( nr[k1] >= (1<<mijl) && (nr[k1]>>mijl)&1 == 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] >= (1<<mijl) && (nr[k1]>>mijl)&1 == 1 ){
            rez=nr[1];
            for( i = 2; i <= k1; i++ )
                rez=rez&nr[i];
            st=mijl+1;
            maxi=max(maxi,rez);
        }
        else
            dr=mijl-1;
    }
    cout<<maxi;
    return 0;
}