#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
//using ordered_set<T> = template<T> tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//using ordered_multiset<T>=template<T> tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
#define endl '\n'
#define X first
#define Y second
#define ll long long

using namespace std;
const int MAXN=1000010;
int n,k;
int a[MAXN];
void read()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
}
bool check(int val)
{
    int cnt=0;
    int cval=0;
    for(int i=1;i<=n;i++)
    {
        cval|=a[i];
        if((cval&val)==val)
        {
            cnt++;
            cval=0;
        }
    }
    return cnt>=k;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    read();
    int ans=0;
    for(int i=30;i>=0;i--)
    {
        int tans=ans+(1<<i);
        if(check(tans))ans=tans;
    }
    cout<<ans<<endl;
    return 0;
}
