#include <cstdio>
#include <cstring>

#define LSB(x) (x&(-x))
#define Z 500001
#define MAX 1000005
#define LEN 800008

int v[MAX],A[LEN],min[LEN];

inline void add(int x,int val)
{
	while(x<MAX)
	{
		v[x]+=val;
		x+=LSB(x);
	}
}

inline int sum(int x)
{
	int s=0;
	while(x>0)
	{
		s+=v[x];
		x-=LSB(x);
	}
	return s;
}

int main()
{
	int i,N,K,sol;
	freopen("echilibru.in","r",stdin);
	
	scanf("%d%d",&N,&K);
	for(i=1;i<=N;i++)
	{
		scanf("%d",&A[i]);
		A[i]+=Z;
	}
	
	memset(v,0,sizeof(v));
	memset(min,0,sizeof(min));
	for(i=1;i<=K;i++) add(A[i],1);
	for(i=K+1;i<=N-K;i++)
	{
		min[i]=sum(A[i]-1);
		add(A[i-K],-1);
		add(A[i],1);
	}
	
	memset(v,0,sizeof(v));
	for(i=N;i>N-K;i--) add(A[i],1);
	for(i=N-K;i>K;i--)
	{
		min[i]+=sum(A[i]-1);
		add(A[i+K],-1);
		add(A[i],1);
	}
	
	sol=0;
	for(i=K;i<=N-K;i++)
		if(min[i]==K) sol++;
	
	freopen("echilibru.out","w",stdout);
		
	printf("%d\n",sol);
	
	return 0;
}
