#ifdef EVAL
#include <bits/stdc++.h>
#else

#endif
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int main() {
    int n, kk;
    cin >> n >> kk;
    vector<int> a(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int ans = 0;
    for (int k = 30; k >= 0; k--) {
        ans ^= 1 << k;

        int left = kk - 1;
        int cur = 0;
        bool ok = false;
        for (int i = 0; i < n; i++) {
            cur |= a[i];

            if ((ans & cur) == ans) {
                if (left) {
                    left--;
                    cur = 0;
                } else {
                    ok = true;
                    break;
                }
            }
        }
        if (!ok) ans ^= (1 << k);
    }
    cout << ans;
}

