#include <bits/stdc++.h>
#define int long long 
#define endl '\n'

using namespace std;

const int MAXN = 2005;
int a[MAXN + 5], dp[MAXN + 5][MAXN + 5];

signed main()
{
    srand(time(0));
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr); std::cout.tie(nullptr);


    int n, k; cin >> n >> k;

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

    dp[1][1] = a[1];

    for(int i = 2; i <= n; i++)
    {
        for(int br = 1; br <= min(i, k); br++)
        {
            int curr = a[i];
            for(int j = i; j > 0; j--)
            {
                if(j < br - 1)break;
                if(j != i)curr |= a[j];
                if(br == 1 && j != 1)continue;
                if(j == 1)
                {
                    if(br == 1)dp[i][br] = max(dp[i][br], curr);
                    continue;
                }

                dp[i][br] = max(dp[i][br], dp[j - 1][br - 1] & curr);
            }
        }
    }

    //cout << (1 & 2) << endl;

    cout << dp[n][k] << endl;
    return 0;
}

