#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#define NMAX 1000000

using namespace std;

int backtrack(int n, int k, int last, int s);

bitset<NMAX+2> x;
int v[NMAX+2];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    bool first = true,c2 = true;
    int n,k,operatii = 1,y;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        if(v[i]!=1)
            c2 = false;
    }
    if(c2 == true)
    {
        int i;
        int st = 0, st1 = 0, dr = 0, dr1=0, s1=0,s2=0;
        for(i=1;i<=n && operatii <k;i++)
        {
            st1 = st | v[i];
            if(st==st1 && v[i]!=0)
            {
                if(first == true)
                {
                    first = false;
                    s1 = st;
                }
                else
                    s1 = s1 & st;
                st1 = v[i];
                operatii++;
            }
            st = st1;
        }
        st = st1 = 0;
        for(;i<=n;i++)
        {
            st1 = st | v[i];
            st = st1;
        }
        s1 = s1 & st1;
        reverse(v+1, v+n);
        first = true;
        for(int i=1;i<=n;i++)
        {
            dr1 = dr | v[i];
            if(dr==dr1 && v[i]!=0)
            {
                if(first == true)
                {
                    first = false;
                    s2 = dr;
                }
                else
                    s2 = s2 & dr;
                dr1 = v[i];
            }
            dr = dr1;
        }
        dr = dr1 = 0;
        for(;i<=n;i++)
        {
            dr1 = dr | v[i];
            dr = dr1;
        }
        s2 = s2 & dr1;
        cout<<max(s1,s2);
    }
    else
        cout<<backtrack(n,k,1,1);
    return 0;
}

int backtrack(int n, int k, int last, int s)
{
    if(s==k)
    {
        bool first = true;
        int t=0;
        int st = 0;
        for(int i=1;i<=n;i++)
        {
            if(x[i]==1)
            {
                if(first==true)
                {
                    t = st;
                    first = false;
                }
                else
                    t = t & st;
                st = v[i];
            }
            st = st | v[i];
        }
        return t;
    }
    int depus = k-s;
    int ans = -1;
    for(int i = last+1;i<=n-depus;i++)
    {
        x[i] = 1;
        ans = max(ans,backtrack(n,k,i,s+1));
        x[i] = 0;
    }
    return ans;
}
