#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

const int maxn = 1e6 + 7;
int n, k;
int a[maxn];
//pair <int, pii> dp[maxn][maxn];
vector <int> v[64];
int br[64];
int shape[maxn];
void read_solve()
{
    cin >> n >> k;
    int sum = 0;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
        sum = (sum | a[i]);
    }
    if(k == 1)
    {
        cout << sum << endl;
        return;
    }
    shape[0] = 1;
    for(int i = 1;i <= 30;i++)
    {
        shape[i] = shape[i - 1] * 2;
    }
    for(int i = 1;i <= n;i++)
    {
        for(int j = 0;j <= 30;j++)
        {
            if((shape[j] & a[i]) == shape[j])
            {
                v[j].push_back(i);
                br[j]++;
            }
        }
    }
    int ans = 0;
    int last = 0;
    for(int i = 0;i <= 30;i++)
    {
        if(br[i] < k)continue;
        vector <int> s;
        int t = 0;
        for(int j = 1;j < v[i][1];j++)
        {
            t = (t | a[j]);
        }
        s.push_back(t);
        for(int j = 1;j < v[i].size() - 1;j++)
        {
            t = 0;
            int z = j;
            while(z < v[i][j + 1])
            {
                t = (t | a[j]);
                z++;
            }
            s.push_back(t);
        }
        t = 0;
        for(int j = v[i][v[i].size() - 1];j <= n;j++)
        {
            t = (t | a[j]);
        }
        s.push_back(t);
        sort(s.begin(),s.end());
        reverse(s.begin(), s.end());
        t = s[0];
        for(int i = 1;i < k;i++)
        {
            t = (t & s[i]);
        }
        cout << t << endl;
        ans = max(ans, t);
    }
    cout << ans << endl;
    return;
}


int main()
{
    speed();
    read_solve();
    return 0;
}
