#include <iostream>

using namespace std;

int v[1000001];
int vc[1000001];
int n,k;

void verificare(int& rez)
{
    int cnt = 0;
    int nr = v[1];
    int ok = 0;
    for (int i = 2; i <= n; i++)
    {
        if (vc[i] == 1)
        {
            if (ok == 0)
            {
                cnt = nr;
            }
            else
            {
                cnt = cnt & nr;
            }
            ok = 1;
            nr = v[i];
        }
        else
        {
            nr = nr | v[i];
        }
    }
    cnt = cnt & nr;
    rez = max(rez , cnt);
}

void bkt (int x , int& rez , int in)
{
    if (x == k)
    {
        verificare(rez);
    }
    else
    {
        for (int i = in + 1; i <= n; i++)
        {
            if (vc[i] == 0)
            {
                vc[i] = 1;
                bkt(x + 1 , rez , i);
                vc[i] = 0;
            }
        }
    }
}

int main()
{
    cin >>n>>k;
    int subtask2 = 0;
    int subtask3 = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >>v[i];
        if (v[i] <= 1)
        {
            subtask2++;
        }
        if (v[i] <= 2)
        {
            subtask3++;
        }
    }
    if (subtask2 == n)
    {
        int nr = 0;
        for (int i = 1; i <= n; i++)
        {
            if (v[i] == 1)
            {
                nr++;
            }
        }
        if (nr >= k)
        {
            cout <<"1";
        }
        else
        {
            cout <<"0";
        }
        return 0;
    }
    else if (subtask3 == n)
    {
        cout <<"3";
        return 0;
    }
    int rez = 0;
    bkt(1 , rez , 1);
    cout <<rez;
    return 0;
}
