#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    long long n, k, qanak=1, bajanac=1, sum, max_sum=-1, hima_s, naxord_s, hima_a, naxord_a=0;
    cin>>n>>k;
    vector <long long> a(n);
    vector <bool> b(n-1);
    vector <long long> c(k+1);        // tex
    vector <long long> d(k);
    for (long long i = 0; i < n; i++) {
        cin>>a[i];
    }
    if (n==1) {
        cout<<'1';
        return 0;
    }
    for (long long i=0; i<k-1; ++i) {
        b[n-2-i] = 1;
    }
    for (long long i = n-1; i>n-k; i--) {
        qanak*=i;
        bajanac*=n-i;
    }
    qanak=qanak/bajanac;
//___________________________________________________________________________________________________________ esqany perfect
    for (long long i=0; i<qanak; i++) {
        for (long long j=1; j<k; ++j) {
            c[j]=0;
        }
        for (long long j=0; j<k; ++j) {
            d[j]=0;
        }
        c[0]=0;
        c[k]=n;
        long long l=1;
        for (long long j=0; j<n; ++j) {
            if (b[j]==1) {
                c[l]=j+1;
                l++;
            }
        }
        for (long long j=0; j<k; ++j) {
            for (long long o=c[j]; o<c[j+1]; ++o) {
                d[j]= d[j] | a[o];
            }
        }
        sum=d[0];
        for (long long j=1; j<k; ++j) {
            sum=sum & d[j];
        }
        if (sum>max_sum) {
            max_sum=sum;
        }
        next_permutation(b.begin(), b.end());
    }
    cout<<max_sum;


}
