#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define ls(v) (int)v.size()
#define pb push_back
const int N = 25;
signed main(){
    // freopen("file.in", "r", stdin);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(auto &it:a) cin >> it;
    int ans = 0;
    for(int i = 1;i<(1 << n);++i){
        int cnt = 0;
        for(int j = 0;j<n;++j) cnt += i >> j & 1;
        if(i&1 == 0 or i >> (n - 1) & 1 == 0 or cnt != k) continue;
        vector<int> v;
        int x = a[0];
        for(int j = 1;j<n;++j){
            if(i >> j & 1){
                v.pb(x);
                x = a[j];
            }
            else{
                x |= a[j];
            }
        }
        v.pb(x);
        int res = v[0];
        for(int j = 1;j<ls(v);++j) res &= v[j];
        ans = max(ans, res);
    }
    cout << ans << endl;
}