#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];
int br[maxn];
int shape[maxn];
void read_solve()
{
    cin >> n >> k;
    int sum = 0;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 7;i >= 1;i--)
    {
        int br = 0;
        int t = 0;
        for(int j = 1;j <= n;j++)
        {
            t = (t | a[j]);
            if((i & t) == i)
            {
                br++;
                t = 0;
                //cout << i << " " << a[j] << " " << j << endl;
            }
        }
        if(br >= k)
        {
            cout << i << endl;
            return;
        }
    }
}


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