#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e6+5;
int aS[N];
int br[N];
  int n,k;
int groups1()
{
    int i=0,groups=0;
    bool nam[3]={0,0,0};
    while(i<n){
        while((!nam[1]||!nam[2]) &&i<n){
            nam[aS[i]]=1;
            ++i;
        }
        if((nam[1]&&nam[2])==0)break;
        nam[1]=0,nam[2]=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;
  if(br[2]>=k)out|=2;
  int gr=groups1();
  //cerr<<gr<<endl;
  if(br[2]>0){if(gr>=k)out|=1;}
  else if(br[1]>=k)out|=1;

  cout<<out<<endl;
}
