#include <bits/stdc++.h>
using namespace std;
//#define int long long
signed main()
{
    ios :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    vector <int> a(n + 1);
    int mx = 0;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
        mx = max(mx,a[i]);
    }
    int bits = log2(mx) + 1;
    for(int vl = (1 << bits) - 1;vl >= 0;vl--)
    {
        int gr = 0;
        vector <int> bts;
        for(int i = 0;i < 20;i++)
        {
            if(vl & (1 << i))
            {
                bts.push_back(i);
            }
        }
        vector <int> used(20);
        int sm = 0;
        for(int i = 1;i <= n;i++)
        {
            for(int j = 0;j < bts.size();j++)
            {
                int bt = bts[j];
                if(!used[j] && (a[i] & (1 << bt)))
                {
                    used[j] = 1;
                    sm++;
                }
            }
            if(sm == bts.size())
            {
                sm = 0;
                gr++;
                for(int j = 0;j < bts.size();j++)
                {
                    used[j] = 0;
                }
            }
        }
        if(gr >= k)
        {
            cout << vl;
            return 0;
        }
    }
}
