#include <bits/stdc++.h>

using namespace std;

typedef int64_t ll;

void solve () {
    ll n, k; cin >> n >> k;

    vector<ll> v(n);
    for (ll& x : v) cin >> x;

    ll res = 0;
    for (ll i = 1; i <= (1 << n); ++i) {
        vector<ll> cors;
        bool tf = false;
        for (ll j = 0; j < n; ++j) {
            if (i & (1 << j)) {
                cors.push_back(j + 1);
                if (j == n) {
                    tf = true;
                }
            }
        }

        if (cors.size() == k - 1 && !tf) {
            vector<ll> anss;

            cors.push_back(n);
            

            ll f = 0;
            for (ll c : cors) {
                ll ans = 0;
                for (ll j = f; j < c; ++j) {
                    ans |= v[j];
                }
                anss.push_back(ans);
                f = c;
            }

            ll cur_res = anss[0];
            for (ll i = 1; i < anss.size(); ++i) {
                cur_res = (cur_res & anss[i]);
            }

            //cout << cur_res << endl;
            res = max(res, cur_res);

        }
        
    }

    cout << res << endl;

}

signed main () {
    ll t = 1; //cin >> t;

    for (ll cs = 1; cs <= t; ++cs) {
        // cout << "Case " << cs << ": " << endl;
        solve ();
    }
}   