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

void solve(){
    // jogaba binary search etmeli for 100 point
    cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    // egerde jogap 3 boljak bolsa dine we dine k sany 3 bolmaly
    // egerde jogap 2 boljak bolsa onda 11 yada 10 gelmeli
    // egerde jogap 1 boljak bolsa onda 1 yada 10 gelmeli
    // check 3
    int sum = 0 , co = 0;
    for(int i = 1; i <= n; i++){
        sum |= a[i];
        if(sum == 3){
            co++;
            sum = 0;
        }
    }
    if(co >= k){
        cout << 3 << endl;
        return;
    }
    // check 2;
    co = 0;
    sum = 0;
    for(int i = 1; i <= n; i++){
        sum |= a[i];
        if(sum == 3 or sum == 2){
            co++;
            sum = 0;
        }
    }
    if(co >= k){
        cout << 2 << endl;
        return;
    } 
    // check 1;
    sum = 0;
    co = 0;
    for(int i = 1; i <= n; i++){
        sum |= a[i];
        if(sum == 3 or sum == 1){
            co++;
            sum = 0;
        }
    }
    if(co >= k){
        cout << 1 << endl;
        return;
    }
    cout << 0 << endl;
}

int main(){
    solve();
}