#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int curcnt[33];
bool hasBit[33];
bool possible(unsigned int x, int K, int N, vector<int> &A)
{
    fill(curcnt, curcnt + 32, 0);
    int m = x;
    int curbit = 0;
    while(m)
    {
        int bit = m & 1;
        if(bit) hasBit[curbit] = true;
        else hasBit[curbit] = false;
        curbit++;
        m = m>>1;
    }
    int ans = 0;
    for(int i = 0; i < N; i++)
    {
        int cur1 = A[i];
        m = x;
        curbit = 0;
        bool bl = true;
        while(m)
        {
            int bit = 0;
            if(cur1) bit = cur1 & 1;
            if(bit && cur1) curcnt[curbit]++;
            if(hasBit[curbit] && curcnt[curbit] == 0) bl = false;
            curbit++;
            if(cur1) cur1 = cur1>>1;
            m = m>>1;
        }
        curbit = 0;
        if(bl)
        {
            int temp = x;
            while(temp)
            {
                int bit = temp & 1;
                if(bit) curcnt[curbit] = 0;
                curbit++;
                temp = temp>>1;
            }
            ans++;
        }
    }
    if(ans < K) return false;
    else return true;
}
int main()
{
    int N, K;
    cin>>N>>K;
    vector<int> A(N);
    int maxA = 0;
    for(int i = 0; i < N; i++) cin>>A[i];
    for(int i = 0; i < N; i++) maxA = max(maxA, A[i]);
    bool found = false;
    int ans = 0;
    int uBound = log2(maxA);
    unsigned int l = 0, r = 1<<uBound;
    while(l < r)
    {
        unsigned int cur = (l+r+1)/2;
        if(possible(cur, K, N, A)) l = cur;
        else r = cur-1;
    }
    cout<<l<<"\n";
    return 0;
}
