#include <iostream>
#include <cstring>
#include <algorithm>
#include <istream>
using namespace std;

int main() {
    iostream::sync_with_stdio(false),cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    long long a[55];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    long long pref[55];
    pref[0] = 0;
    for (int i = 1; i <= n; i++) {
        pref[i] = pref[i-1] + a[i];
    }

    long long ans = 0;
    for (int bit = 50; bit >= 0; bit--) {
        long long peop = ans | (1LL << bit);
        bool dp[55][55];
        memset(dp, 0, sizeof(dp));
        dp[0][0] = true;

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= min(i, k); j++) {
                dp[i][j] = false;
                for (int p = j-1; p < i; p++) {
                    if (dp[p][j-1]) {
                        long long seg_sum = pref[i] - pref[p];
                        if ((seg_sum & peop) == peop) {
                            dp[i][j] = true;
                            break;
                        }
                    }
                }
            }
        }

        if (dp[n][k]) {
            ans = peop;
        }
    }

    cout << ans << endl;
    return 0;
}