#include <bits/stdc++.h>
#define int long long

using namespace std;

const int MAXN = 1e6;

bool iz[MAXN + 5];
int n, k, a[MAXN + 5], ans;

void check()
{
    int curr = 0, orr = 0, br = 0;
    for(int i = 1; i <= n; i++)
    {
        if(orr == 0)orr = a[i];
        else orr |= a[i];

        if(iz[i])
        {
            if(br == 0)curr = orr;
            else curr &= orr;

            orr = 0; br++;
        }
        else if(i == n)
        {
            if(br == 0)curr = orr;
            else curr &= orr;
        }
    }

    if(br == k - 1)
    {
        if(ans < curr)
        {
            ans = curr;
        }
    }
}

void rec(int pos)
{
    if(pos == n)
    {
        check();
        return;
    }

    iz[pos] = true;
    rec(pos + 1);
    iz[pos] = false;
    rec(pos + 1);
}

signed main()
{
    srand(time(0));
    //std::ios_base::sync_with_stdio(false);
    //std::cin.tie(nullptr); std::cout.tie(nullptr);


    cin >> n >> k;
    int mx =0;

    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        mx = max(mx, a[i]);
    }

    rec(1);
    cout << ans << endl;

    /*
    for(int i = 1; i <= 10; i++)
    {

        int cur = i;
        string s;

        while(cur != 0)
        {
            s.push_back((cur % 2) + '0');
            cur /= 2;
        }

        reverse(s.begin(), s.end());

        cout << s << endl;


    }
    */

    return 0;
}
