#include <iostream>
#include <vector>
using namespace std;

int main(void){
    // freopen("input.txt","r",stdin);
    vector<int> arr;
    int n, k;
    cin>>n>>k;
    int c1 = 0, c2 = 0;
    for(int i = 0; i<n; i++){
        int a; cin>>a;
        if(a!=0) arr.push_back(a);
        if(a == 1) c1++;
        if(a == 2) c2++;
    }

    if(c2 < k){
        if(c1 < k) cout<<0<<endl;
        else cout<<1<<endl;
        return 0;
    }

    n = arr.size();
    vector<int> dp(n+1, 0);
    int ind1 = -1, ind2 = -1;

    for(int i = 1; i<=n; i++){
        if(arr[i-1] == 2){
            dp[i] = 1 + ((ind1==-1)?(-1):(dp[ind1]));
            ind2 = i-1;
        }
        else{
            dp[i] = 1 + ((ind2==-1)?(-1):(dp[ind2]));
            ind1 = i-1;
        }
    }

    if(dp[n] >= k) cout<<3<<endl;
    else cout<<2<<endl;
    return 0;
}