#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int N=1e6+5,BITS=33;
int aS[N];
int br[BITS];
int n,k;
vector<int> bitsOfNumber(int e)
{
    vector<int> bits;
    int i=0;
    while(e>0)
    {
        if(e&1)bits.push_back(i);
        ++i;
        e>>=1;
    }
    return bits;
}
int groups(vector<int> vazhniBitove)
{
    int i=0,groups=0;
    bool nam[BITS];
    fill_n(nam,BITS,0);
    while(i<n)
    {
        while(i<n)
        {
            int andOfThem=1;
            for(auto e:vazhniBitove)andOfThem&=nam[e];
            if(andOfThem)break;
            for(auto b:bitsOfNumber(aS[i]))
                nam[b]=1;
            ++i;
        }
        int andOfThem=1;
        for(auto e:vazhniBitove)andOfThem&=nam[e];
        if(andOfThem==0)break;
        //cerr<<i<<" "<<andOfThem<<endl;
        fill_n(nam,BITS,0);
        ++groups;
    }
    return groups;
}
int main()
{
    cin>>n>>k;
    for(int i=0; i<n; ++i)cin>>aS[i];
    for(int i=0; i<n; ++i)++br[aS[i]];
    int out=0;
    vector<int> vazhniBits;
    if(br[2]>=k)out|=2,vazhniBits.push_back(1);
    vazhniBits.push_back(0);
    int gr=groups(vazhniBits);
    //cerr<<gr<<endl;
    if(gr>=k)out|=1;

    cout<<out<<endl;
}
