#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 = 1e6 + 7;
int n, k;
int a[maxn];
int p[maxn];
int ans = 0;
void check()
{
    int t = 0;
    int tek =  -1;
    t = a[1];
    if(p[n] != k)return;
    for(int i = 2;i <= n;i++)
    {
        if(p[i] == p[i - 1])
        {
            t = (t | a[i]);
        }
        else
        {
            if(tek == -1)tek = t;
            else tek = (tek & t);
            t = a[i];
        }
    }
    if(tek == -1)tek = t;
    else tek = (tek & t);
    ans = max(tek, ans);
}
void rec(int pos)
{
    for(int i = 0;i <= 1;i++)
    {
        if(i == 0)
        {
            p[pos] = p[pos - 1];
        }
        if(i == 1)
        {
            p[pos] = p[pos - 1] + 1;
        }
        if(pos == 1)p[pos] = 1;
        if(p[pos] > k)p[pos] = k;
        if(pos == n)check();
        else rec(pos + 1);
    }
}
void read_solve()
{
    cin >> n >> k;
    int sum = 0;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
        sum = (sum | a[i]);
    }
    rec(1);
    cout << ans << endl;
}


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