#include <bits/stdc++.h>

using namespace std;

long long n, k, v[1000001], nr, i, j, maxi, sol[1000001];

void bkt ( long long x, long long sum ) {
    if ( x <= k ) {
        for ( sol[x] = 1; sol[x]+sum <= n; sol[x]++ ) {
            bkt ( x+1, sum+sol[x] );
        }
    }
    else {
        if ( sum == n ) {
            long long m = 1, auxi, rf = -1;
            for ( i = 1; i <= k; i++ ) {
                auxi = v[m];
                j = m+1;
                m += sol[i];
                while ( j < m ) {
                    auxi = ( auxi | v[j] );
                    j++;
                }
                if ( rf == -1 ) {
                    rf = auxi;
                }
                else {
                    rf = ( rf & auxi );
                }
            }
            maxi = max ( maxi, rf );
        }
    }
}

int main()
{
    cin >> n >> k;

    for ( i = 1; i <= n; i++ ) {
        cin >> v[i];
    }

    bkt ( 1, 0 );

    cout << maxi;

    return 0;
}
