#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 curAnd = (1 << 15) - 1;

    for(pair<int, int> &p : ranges)
    {
        int curOr = 0;
        for(int i=p.first; i<=p.second; i++)curOr = (curOr | v[i]);
        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;
}
