#pragma GCC optimize("Ofast","unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define pii pair<int,int>
#define vc vector
#define pb push_back
#define all(x) x.begin(),x.end()
#define popcount(x) __builtin_popcount(x)

vc<int> solve(vc<int> a) {
    int n = a.size();
    vc<int> ans1,ans2;
    int mn = INT_MAX;
    for (int mask = 0; mask <(1 << n) ; mask ++) {
        vc<int> a1,b1;
        int sum1=0,sum2=0, cnt1=0,cnt2=0;
        for (int i=0;i<n;i++) {
            if (mask & (1<<i)) {
                sum1+=a[i];
                a1.pb(i);
                cnt1++;
            }else {
                sum2+=a[i];
                b1.pb(i);
                cnt2++;
            }
        }
        if (mask == 185) {
            cout << sum1 << ' ' << sum2 << '\n';
        }
        if (abs(cnt1-cnt2) < mn) {
            mn = abs(cnt1-cnt2);
            if (sum1>sum2) {
                ans1 = a1;
                ans2 = b1;
            }else {
                ans1=b1;
                ans2=a1;
            }
        }
    }
    vc<int> ans(n);
    for (int i=0;i<n;i++) {
        if (i<ans1.size()) ans[i] = ans1[i];
        else ans[i] = ans2[i-ans1.size()];
    }
    return ans;

}
pii chmax(pii a,pii b) {
    if (a.first > b.first) return a;
    return b;
}
int main() {
    cin.tie(nullptr) -> sync_with_stdio(false);
    cout.tie(nullptr);

    int n,K; cin >> n >> K;

    vc<int> a(n+1);
    for (int i=1;i<=n;i++) cin >> a[i];

    queue<array<int,4>> q;
    q.push({1,a[1],0,1});
    q.push({1,(1<<n)-1,a[1],0});
    int mx = 0;
    while (!q.empty()) {
        auto [i,s,l,k] = q.front(); q.pop();
        if (k == K) mx = max (mx, s);
        if (i+1 <=n) {
            if (k+1<=K) {
                q.push({i+1,s & (l|a[i+1]),0, k+1});
            }
            q.push({i+1,s,l | a[i+1],k});
        }
    }
    cout << mx;

}