#include<iostream>
#include<vector>
using namespace std;
int cnt[33];
bool possible(int x, int K, int N, vector<int> &A)
{
    int curcnt[33];
    fill(curcnt, curcnt + 32, 0);
    int cur = x;
    int curbit = 0;
    int ans = 0;
    for(int i = 0; i < N; i++)
    {
        int cur1 = A[i];
        int curbit = 0;
        while(cur1)
        {
            int bit = cur1 & 1;
            if(bit) curcnt[curbit]++;
            curbit++;
            cur1 = cur1>>1;
        }
        int temp = cur;
        bool bl = true;
        curbit = 0;
        while(temp && bl)
        {
            int bit = temp & 1;
            if(bit)
            {
                if(curcnt[curbit] == 0) bl = false;
            }
            curbit++;
            temp = temp>>1;
        }
        curbit = 0;
        if(bl)
        {
            temp = cur;
            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]);
        int cur = A[i];
        int curbit = 0;
        while(cur)
        {
            int bit = cur & 1;
            if(bit) cnt[curbit]++;
            curbit++;
            cur = cur>>1;
        }
    }
    bool found = false;
    int ans = 0;
    for(int i = maxA; i > 0 && !found; i--)
    {
        if(possible(i, K, N, A))
        {
            found = true;
            ans = i;
        }
    }
    cout<<ans<<"\n";
    return 0;
}
