/*
  _      __        __         __        ____                    ___    _                   __
 | | /| / / ___ _ / /_ ____  / /       / __ \  ___  ___        / _ \  (_) ___  ____ ___   / /
 | |/ |/ / / _ `// __// __/ / _ \     / /_/ / / _ \/ -_)      / ___/ / / / -_)/ __// -_) /_/ 
 |__/|__/  \_,_/ \__/ \__/ /_//_/     \____/ /_//_/\__/      /_/    /_/  \__/ \__/ \__/ (_)  
                                                                                             
*/
 
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define allr(v, l, r) v.begin() + l, v.begin() + r;
#define endl "\n"
#define newline cout << endl;
using namespace std;

// constants
const int INF = 1e9;
const int LOG = 30;

// functions

// structs

// globals

// notes
/*
 -stuff you should look for-
* int overflow, array bounds
* special cases (n=1?)
* do something instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH

continue - skip the rest in the loop
*/

void solve()
{
    int n, K;
    cin >> n >> K;
    vector <int> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    
    auto in = [&](int x, int y) -> bool
    {
        return (x & y) == x;
    };
    
    int res = 0;
    for (int b = LOG; b >= 0; b--)
    {
        int cur = 0, subc = 0;
        for (int i = 1; i <= n; i++)
        {
            cur |= a[i];
            if (in(1 << b | res, cur))
            {
                subc++, cur = 0;
            }
        }
        
        if (subc >= K)
        {
            res |= (1 << b);
        }
    }
    
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int testcases = 1;
    // cin >> testcases;
    while (testcases--)
    {
        solve();
        newline
    }
}

/*
$$$$$$$$\ $$$$$$$$\ 
$$  _____|\____$$  |
$$ |          $$  / 
$$$$$\       $$  /  
$$  __|     $$  /   
$$ |       $$  /    
$$$$$$$$\ $$$$$$$$\ 
\________|\________|
*/