#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl "\n"
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define sz(s) (int)(s.size())
#define gcd __gcd
using pii = pair<int, int>;



/*int n, k;
    cin >> n >> k;
    vector<vector<int>> bit(33);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        for (int j = 0; j < 33; ++j) {
            if ((a[i] >> j) & 1) {
                bit[j].push_back(a[i]);
            }
        }
    }
    vector<vector<int>> pos(33, vector<int>(n + 1, -1));
    for (int j = 0; j < 33; ++j) {
        int prev = -1;
        for (int i = n - 1; i > -1; --i) {
            if ((a[i] >> j) & 1) {
                prev = i;
            }
            pos[j][i] = prev;
        }
        reverse(all(pos[j]));
    }

    vector<int> tr;
    int ans = 0;
    for (int i = 32; i > -1; --i) {
        if (sz(bit[i]) < k) continue;
        // ans |= (1ll << i);
        cout << "i: " << i << endl;
        int cnt = 0;
        bool fl = false;
        int last = -1;
        for (auto x : bit[i]) {
            cout << x << " " << last << " " << fl << " " << cnt << endl;
            if (cnt >= k) break;
            if (x <= last) continue;
            if (fl) break;
            int mx = x;
            for (auto y : tr) {
                if (pos[y][last + 1] == -1) {
                    fl = true;
                    break;
                }
                mx = max(mx, pos[y][last + 1]);
            }
            last = mx;
            cnt++;
        }
        if (cnt < k) {cout << "YES" << endl;fl = true;}
        if (!fl) {
            tr.push_back(i);
            ans += (1ll << i);
        }
        cout << endl;
    }
    cout << ans << endl;
*/


void solve() {
    int n, k;
    cin >> n >> k;
    vector<vector<int>> bit(33);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        for (int j = 0; j < 33; ++j) {
            if ((a[i] >> j) & 1) {
                bit[j].push_back(a[i]);
            }
        }
    }
    vector<vector<int>> dp(k + 1, vector<int>(n + 1, 0));
    int res = 0;
    for (int i = 1; i <= n; ++i) {
        res |= a[i - 1];
        dp[1][i] = res;
    }
    for (int i = 2; i <= k; ++i) {
        for (int j = i; j <= n; ++j) {
            for (int p = i - 1; p < j; ++p) {
                int res = 0;
                for (int q = p + 1; q <= j; ++q) {
                    res |= a[q - 1];
                }
                // cout << "I: " << i << " J: " << j << " P: " << p << " OR from p to j: " << res << endl;
                dp[i][j] = max(dp[i][j], dp[i - 1][p] & res);
            }
        }
    }
    cout << dp[k][n] << endl;
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int tt =1 ;
    // cin >> tt;
    while (tt --) {
        solve();
    }
    return 0;
}
