#include <bits/stdc++.h>
using namespace std;

//#define DEBUG

#ifdef DEBUG
    #define D(x) cout << "    " << #x << " = " << x << endl;
    #define V(x) cout << "    " << #x << ": "; for(auto i : x) cout << i << ' '; cout << endl;
    #define N() cout << endl;
#else
    #define D(X)
    #define V(X)
    #define N()
#endif

const int INT_LEN = 31;

int n, k;
vector<int> inp;

vector<int> maxies;

int get_bit_at_pos(int num, int b)
{
    int mask = 1;
    mask = mask << (INT_LEN - b - 1);
    return (num & mask) != 0;
}

int calc_maxies_for_bit(int b)
{
    vector<int> bit_maxies;
    vector<int> nw_maxies;

    for(int i = 0;i < n;i++)
    {
        if(get_bit_at_pos(inp[i], b) == 1)
        {
            bit_maxies.push_back(i);
        }
    }

    if(bit_maxies.size() > 0) bit_maxies[bit_maxies.size() - 1] = n - 1;

    V(bit_maxies)

    if(bit_maxies.size() < k) return 0;

    int i = 0;
    int j = 0;

    int last_mx = -1;

    while(i < bit_maxies.size() && j < maxies.size())
    {
        int bm = bit_maxies[i];
        int ma = maxies[j];

        if(bm <= last_mx)
        {
            i++;
            continue;
        }

        if(ma <= last_mx)
        {
            j++;
            continue;
        }

        int nw = max(bm, ma);

        last_mx = nw;

        nw_maxies.push_back(nw);

        i++;
        j++;
    }

    if(nw_maxies.size() < k) return 0;

    maxies = nw_maxies;

    V(nw_maxies)

    return 1;
}

int main()
{
    cin >> n >> k;

    for(int i = 0;i < n;i++)
    {
        int x;
        cin >> x;
        inp.push_back(x);
    }

    #ifdef DEBUG
        //for(int i = 0;i < INT_LEN;i++) D(get_bit_at_pos(9, i));
    #endif

    for(int i = 0;i < n;i++)
    {
        maxies.push_back(i);
    }

    int res = 0;

    for(int i = 0;i < INT_LEN;i++)
    {
        res = res * 2 + calc_maxies_for_bit(i);
    }

    cout << res;
}