#include <bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

const int MAXN = 1e6;
int n, k, a[MAXN + 5], dp[MAXN + 5][MAXN + 5];

bool check(int m)
{
    int orr = 0, br = 0;
    for(int i = 1; i <= n; i++)
    {
        orr |= a[i];

        bool flag = true;
        for(int bit = 0; bit < 15; bit++)
        {
            if(m & (1 << bit))
            {
                if(!(orr & (1 << bit)))
                {
                    flag = false;
                    break;
                }
            }
        }

        if(flag)
        {
            br++;
            orr = 0;
        }
    }

    return br >= k;
}

signed main()
{
    srand(time(0));
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr); std::cout.tie(nullptr);


    cin >> n >> k;

    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }

    /*
    for(int i = 1; i <= 10; i++)
    {

        int cur = i;
        string s;

        while(cur != 0)
        {
            s.push_back((cur % 2) + '0');
            cur /= 2;
        }

        reverse(s.begin(), s.end());

        cout << s << endl;


    }
    */

    for(int i = 3000; i >= 0; i--)
    {
        if(check(i))
        {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}
