#include <bits/stdc++.h>
using namespace std;

int a[200000];

int main() {
    int n, k; scanf("%d%d", &n, &k);

    for(int i=0;i<n;++i){
        int c; scanf("%d", &c);
        a[i] = c;
    }

    int cnt=0, cnt1=0, cnt2=0;
    bool found1=false, found2=false;
    for(int i=0;i<n;++i){
        if(a[i]==1) cnt1++;
        if(a[i]==2) cnt2++;

        if(a[i]==1 && found1==false) found1=true;
        if(a[i]==2 && found2==false) found2=true;

        if(found1&&found2){
            cnt++;
            found1=false;
            found2=false;
        }
    }

    if(cnt>=k) printf("3");
    else if(cnt2>=k) printf("2");
    else if(cnt1>=k) printf("1");
    else printf("0");
}