#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define ss second
#define ina insert
#define pb push_back
signed main(){
	int n,k;
	cin>>n>>k;
	int x[n];
	for(int i=0; i<n; i++){
		cin>>x[i];
	}
	if(n==1){
		if(x[0]==0){
			cout<<0<<endl;
		}
		else cout<<1<<endl;
		exit(0);
	}
	int l=0;
	if(x[0]==1)l++;
	for(int i=1; i<n; i++){
		if(x[i]==1 && x[i-1]==0){
			l++;
		}
		else{
			if(x[i]==1)l++;
		}
	}
	if(k>l){
		cout<<0<<endl;
	}
	else cout<<1<<endl;
	//cout<<l<<endl;
}