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

int main()
{
    int n, k;
    cin >> n >> k;
    
    vector<vector<int>> bits(30);
    
    int number = 0;
    vector<int> current_ends{};

    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        for(int bit = 0; (1 << bit) <= x; bit++)
        {
            if((x & (1 << bit)))
            {
                bits[bit].emplace_back(i);
            }
        }
    }

    for(int bit = 0; bit < 30; bit++)
    {
        if(!bits[bit].empty() && bits[bit].size() >= k)
        {
            // cout << "\nbit " << bit << ": ";
            // for(auto x : bits[bit])
            // {
            //     cout << x << " ";
            // }
            if(current_ends.empty()) // we have no history
            {
                number = (1 << bit);
                current_ends = bits[bit];
            }
            else
            {
                int fine = 0;
                int idx = 0;
                int last_left = -1;
                vector<int> made{};
                for(auto it = current_ends.begin(); it != current_ends.end(); it++)
                {
                    auto closest_one = (upper_bound(bits[bit].begin(), bits[bit].end(), *it));
                    if(closest_one == bits[bit].begin())
                    {
                        continue;
                    }
                    closest_one--;
                    // cout << last_left + 1 << " " << *closest_one << " " << *it << "\n";
                    if(last_left + 1 <= *closest_one && *closest_one <= *it)
                    {
                        last_left = *it;
                        made.emplace_back(*it);
                        fine++;
                    }
                }
                if(fine < k)
                {
                    number = (1 << bit);
                    current_ends = made;
                }
                else
                {
                    number |= (1 << bit);
                }
            }
        }
    }

    cout << number;
}