#include <iostream>
#include <ios>
#include <vector>

using namespace std;

#define NMAX 1000000
#define LOGMAX 30

struct ura{
    int st, dr;
    int pozfix;
    char inUse;
};

vector <ura> interv;
vector <ura> save;

int v[NMAX + 1];
int frecv[LOGMAX + 1];

void logFrecv(int nr){
    for (int pow = 0; pow <= LOGMAX; pow++){
        if (((1 << pow) & nr) > 0){
            frecv[pow]++;
        }
    }
}

void mergeSecv(int a, int b){
    interv[b].st = interv[a].st;
    interv[a].inUse = -1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, K;
    cin >> N >> K;
    for (int i = 1; i <= N; i++){
        cin >> v[i];
        logFrecv(v[i]);
    }
    int biggest = -1;
    for (int pow = LOGMAX; pow >= 0; pow--){
        if (frecv[pow] >= K){
            biggest = pow;
            break;
        }
    }
    if (biggest == -1){
        cout << 0;
        return 0;
    }
    int nowK = frecv[biggest];
    bool firstUse = 0;
    for (int i = 1; i <= N; i++){
        if (firstUse == 1 && (v[i] & (1 << biggest)) > 0){
            interv.push_back({i, i, -i, 1});
            continue;
        }
        if (i == 1){
            interv.push_back({i, i, -1, 1});
        }
        else{
            interv.back().dr = i;
        }
        if ((v[i] & (1 << biggest)) > 0){
            firstUse = 1;
            interv.back().pozfix = i;
        }
    }
    int rez = (1 << biggest);
    for (int pow = biggest - 1; pow >= 0; pow--){
        save = interv;
        int last = -1, hadLast = -1, lastPoz = -1;
        int saveNowK = nowK;
        bool allHas = 1;
        for (int i = 0; i < interv.size(); i++){
            if (interv[i].inUse == -1){
                continue;
            }
            int hasIt = 0, nowPoz = -1;
            for (int j = interv[i].st; j <= interv[i].dr; j++){
                if ((v[j] & (1 << pow)) > 0){
                    hasIt++;
                    if (hasIt == 1){
                        interv[i].pozfix = max(interv[i].pozfix, j);
                    }
                    nowPoz = j;
                }
            }
            if (hasIt == 0){
                //incercam sa luam de la altul
                if (lastPoz != -1 && lastPoz > interv[last].pozfix){
                    interv[i].st = lastPoz;
                    interv[last].dr = lastPoz - 1;
                    nowPoz = lastPoz;
                }
                else if (lastPoz != -1 && nowK > K){
                    mergeSecv(last, i);
                    nowK--;
                }
                else{
                    allHas = 0;
                    break;
                }
            }
            last = i;
            hadLast = hasIt;
            lastPoz = nowPoz;
        }
        if (allHas == 0){
            interv = save;
            nowK = saveNowK;
        }
        else{
            rez |= (1 << pow);
        }
    }
    cout << rez;
    return 0;
}
