#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 1e6 + 5;
int arr[MAXN], ili[MAXN];
vector<int> ind;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    if(n > 20)
    {
        int br1 = 0, br2 = 0, br12 = 0;
        for(int i = 1; i <= n; i++)
        {
            cin >> arr[i];
            if(arr[i] == 1) br1++;
            else if(arr[i] == 2) br2++;
        }
        bool flag1 = false, flag2 = false;
        for(int i = 1; i <= n; i++)
        {
            if(arr[i] == 1)
            {
                flag1 = true;
            }
            else if(arr[i] == 2)
            {
                flag2 = true;
            }
            if(flag1 && flag2)
            {
                br12++;
                flag1 = false;
                flag2 = false;
            }
        }
        if(br12 >= k) cout << 3 << endl;
        else if(br2 >= k) cout << 2 << endl;
        else if(br1 >= k) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }
    for(int i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }
    for(int l = 1; l <= n - 1; l++)
    {
        for(int r = l + 1; r <= n; r++)
        {
            for(int m = l; m <= r; m++)
            {
                ili[l][r] = ili[l][r - 1] | arr[m];
            }
        }
    }
    int start = 1;
    for(int l = start; l <= n; l++)
    {
        for(int r = l; r <= n; r++)
        {
            if(l == r)
            {
                continue;
            }
            if(ili[l][r] == ili[l][r - 1])
            {
                r--;
                ind.push_back(r);
                l = r;
                break;
            }
        }
    }
    int ans = ili[l][ind[0]];
    for(int i = 1; i < ind.size(); i++)
    {
        ans = ans & ili[ind[i - 1] + 1][ind[i]];
    }
    cout << ans << endl;
    return 0;
}
