#include<stdio.h>
#include<string.h>

#define minim(a,b)(a<b ? a : b)
#define maxim(a,b)(a>b ? a : b)
#define INF 1000000005
#define NMAX 800005
#define VMAX 1000005

int v[NMAX],val=INF,L;
int AIB[VMAX],n,sol=0;
int vmax=-INF;

void update(int poz,int val)
{
	for(;poz && poz<=vmax;poz+=(poz&(poz-1)^poz))
		AIB[poz]+=val;
}

inline int query(int poz)
{
	int s=0;
	for(;poz;poz-=(poz&(poz-1)^poz))
		s+=AIB[poz];
	return s;
}

int main ()
{
	int i,r;
	
	freopen("echilibru.in","r",stdin);
	freopen("echilibru.out","w",stdout);
	scanf("%d%d",&n,&L);
	
	memset(v,0,sizeof(v));
	memset(AIB,0,sizeof(AIB));
	
	for(i=1;i<=n;i++)
	{
		scanf("%d",&v[i]);
		val=minim(val,v[i]);
	}	
	if(val<0)
		for(i=1;i<=n;i++)
			v[i]-=val-1;
	for(i=1;i<=n;i++)
		vmax=maxim(vmax,v[i]);
	for(i=1;i<=2*L+1;i++)
		update(v[i],1);
	for(i=L+1;i<=n-L;i++)
	{
		r=query(v[i]-1);
		if(r==L)
			sol++;
		update(v[i-L],-1);
		update(v[i+L+1],1);
	}
	printf("%d\n",sol);
	
	return 0;
}





