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

int n, k, maxAnd = 0;
vector<int> v;

void proccess(vector<pair<int, int> > ranges)
{
    int curOr = 0;
    for(int i=ranges[0].first; i<=ranges[0].second; i++)curOr = (curOr | v[i]);
    int curAnd = curOr;

    for(int i=1; i<ranges.size(); i++)
    {
        curOr = 0;
        for(int j=ranges[i].first; j<=ranges[i].second; j++)curOr = (curOr | v[j]);
        curAnd = (curAnd & curOr);
    }

    maxAnd = max(maxAnd, curAnd);
}

void generateRanges(vector<pair<int, int> > ranges, int l, int rem)
{
    if(n - l < rem)return;

    if(rem == 1)
    {
        ranges.push_back({l, n});
        proccess(ranges);
        return;
    }

    for(int i=l; i<n; i++)
    {
        ranges.push_back({l, i});
        generateRanges(ranges, i+1, rem-1);
        ranges.pop_back();
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> k;
    v.resize(n);
    for(int &num : v)cin >> num;

    vector<pair<int, int> > ranges;
    generateRanges(ranges, 0, k);
    cout << maxAnd;
}
