#include<cstdio>
void read(),solve();
int i,j,n,L,sol,A[800010],m[800010],M[800010];
int main()
{
	read();
	solve();
	return 0;
}
void read()
{
	freopen("echilibru.in","r",stdin);
	freopen("echilibru.out","w",stdout);
	scanf("%d%d",&n,&L);
	for(i=1;i<=n;i++)scanf("%d",&A[i]);
}
void solve()
{
	for(i=L+1;i<=n+1;i++)
		for(j=i-L;j<=i-1;j++)
		{
			if(A[j]<A[i])++m[i]; else ++M[i];
			if(i-L<2)continue;
			if(A[j]<A[i-L-1])++m[i-L-1]; else ++M[i-L-1];
		}
	for(i=L+1;i<=n-L;i++)if(m[i]==M[i])++sol;
	printf("%d\n",sol);
}