#include <bits/stdc++.h>
#define MAXN 20

using namespace std;

int n, k;
int v[MAXN + 1], per[MAXN], maxi;

int calc(){
    int i, rez, cur, ind;

    rez = -1;
    ind = 1;
    cur = v[0];
    for(i = 1; i < n; i++){
        if(per[ind] == i){
            if(rez == -1){
                rez = cur;
            }else{
                rez = rez & cur;
            }
            cur = v[i];
            ind++;
        }else{
            cur = cur | v[i];
        }
    }
    if(rez == -1){
        rez = cur;
    }else{
        rez = rez & cur;
    }
    return rez;
}

void bkt(int pos, int val){
    int pun, i;
    if(pos == k){
        maxi = max(maxi, calc());
//        printf("calc = %d\n", calc());
//        for(i = 1; i < pos; i++){
//            printf("%d ", per[i]);
//        }
//        printf("\n");
    }else{
        for(pun = val + 1; pun + k - pos <= n; pun++){
            per[pos] = pun;
            bkt(pos + 1, pun);
        }
    }
}

int main()
{
    int i;

    cin >> n >> k;
    for(i = 0; i < n; i++){
        cin >> v[i];
    }
    bkt(1, 0);
    cout << maxi << "\n";
    return 0;
}
