#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

const int maxn = 3e3 + 7;
int n, k;
int a[maxn];
pair <int, pii> dp[maxn][maxn];
void read_solve()
{
    cin >> n >> k;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    int sk = 1;
    int sm = 1;
    for(int i = 1;i <= 31;i++)
    {
        sk *= 2;
        sm += sk;
    }

    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j <= n;j++)
        {
            dp[i][j] = {-1, {-1, sm}};
        }
    }

    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j <= i;j++)
        {
            if(i == 1 && j == 1)
            {
                dp[i][j].X = a[i];
                dp[i][j].Y.X = a[i];
                dp[i][j].Y.Y = sm;
            }
            else if(j == 1)
            {
                dp[i][j].X = (dp[i - 1][j].X | a[i]);
                dp[i][j].Y.X = (dp[i - 1][j].X | a[i]);
                dp[i][j].Y.Y = dp[i - 1][j].Y.Y;
            }
            else
            {
                if(1)
                {
                    dp[i][j].X = (dp[i - 1][j].X & (a[i] | dp[i - 1][j].Y.X));
                    dp[i][j].Y.X = (a[i] | dp[i - 1][j].Y.X);
                    dp[i][j].Y.Y = dp[i - 1][j].Y.Y;
                    dp[i][j].X = (dp[i][j].Y.X & dp[i][j].Y.Y);
                }
                if((a[i] & dp[i - 1][j - 1].X) > dp[i][j].X)
                {
                    dp[i][j].X = (a[i] & dp[i - 1][j - 1].X);
                    dp[i][j].Y.X = a[i];
                    dp[i][j].Y.Y = dp[i - 1][j - 1].X;
                }//cout << dp[i][j].X << " " << dp[i][j].Y.X << " " << dp[i][j].Y.Y << " " << i << " " << j << endl;
            }

        }
    }
    //cout << dp[1][1].X << " " << a[2] << endl;
    //cout << (2 | 5) << endl;
    cout << dp[n][k].X << endl;
}


int main()
{
    speed();
    read_solve();
    return 0;
}
