#include<bits/stdc++.h>
using namespace std;
#define N 1000009
int n , k;
vector<int> v;
int mx = 0;
int a[N];

int check(int x){
    int sum = 0 , co = 0;
    for(int i = 1; i <= n; i++){
        sum |= a[i];
        if(sum == x){
            co++;
            sum = 0;
        }
    }
    if(co >= k){
        return 1;
    }
    return 0;
}

void solve(){
    cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    // check 3;
    int sum = 0 , co = 0;
    for(int i = 1; i <= n; i++){
        sum |= a[i];
        if(sum == 3){
            co++;
            sum = 0;
        }
    }
    if(check(3)){
        cout << 3 << endl;
    }
    else if(check(2)){
        cout << 2 << endl;
    }
    else if(check(1)){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

int main(){
    solve();
}