#include <bits/stdc++.h>

using namespace std;
const int MAXN=2000;
long long a[MAXN];
long long dp[MAXN][MAXN];
int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long n, k;
    cin >> n >> k;

    for (long long i = 0; i < n;i++)
    {
        cin>>a[i];
    }
    for (long long i=0;i<k;i++)
    {
        for (long long j = i; j < n;j ++)
        {
            if (i==0)
            {
                if (j == 0)
                {
                    dp[i][j]=a[j];
                }
                else
                {
                    dp[i][j] = (dp[i][j-1]|a[j]);
                }
            }
            else
            {
                long long maxi = 0, h = 0;
                for (long long q = j; q>=0;q--)
                {
                    maxi = max(maxi, (h&dp[i-1][q]));
                    h = (h|a[q]);
                }
                dp[i][j] = maxi;
            }
        }
    }
    cout << dp[k-1][n-1] << endl;

/*
    for (long long i = 0; i < k; i ++)
    {
        for (long long j = 0; j < n;j ++)
        {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/

}
