# include <cstdio>
# include <algorithm>
# define NMAX 800088

using namespace std;

struct camp
{ int a,ind;}v[NMAX];

int aib[NMAX],maxr[NMAX],maxl[NMAX];
int l,solutii,i,n;

bool cond (camp au, camp beu)
{
	return (au.a>beu.a)||(au.a==beu.a&&au.ind<beu.ind);
}

int bit1(int x)
{
	return (x^(x-1))&x;
}

void updatel (int x);
int queryl (int x);


int main ()
{
	freopen ("echilibru.in","r",stdin);
	freopen ("echilibru.out","w",stdout);
	scanf ("%d%d",&n,&l);
	for (i=1;i<=n;i++)
	{
		scanf("%d",&v[i].a);
		v[i].ind=i;
	}
	// sortez
	sort(v+1,v+n+1,cond);
	// iau maxim stanga
	for (i=0;i<=n+10;i++)
		aib[i]=0;
	for (i=1;i<=n;i++)
	{
		maxl[v[i].ind]=queryl(v[i].ind);
		if (v[i].ind>l+1)
			maxl[v[i].ind]-=queryl(v[i].ind-l-1);
		updatel(v[i].ind);
	}
	
	// inversez dreapta cu stanga
	
	for (i=1;i<=n;i++)
		v[i].ind=n-v[i].ind+1;
	sort(v+1,v+n+1,cond);
	// iau maxim dreapta
	for (i=0;i<=n+10;i++)
		aib[i]=0;
	for (i=1;i<=n;i++)
	{
		maxr[n+1-v[i].ind]=queryl(v[i].ind);
		if (v[i].ind>l+1)
			maxr[n+1-v[i].ind]-=queryl(v[i].ind-l-1);
		updatel(v[i].ind);
	}
	
	// caut

	solutii=0;
	for (i=l+1;i<=n-l;i++)
		{
			if (l==maxr[i]+maxl[i])
				solutii++;
		}
	printf("%d\n",solutii);
	return 0;
}

void updatel (int x)
{
	int i=0;
	for (i=x;i<=n;i+=bit1(i))
		aib[i]++;
}

int queryl (int x)
{
	int suma=0;
	int i=0;
	for (i=x;i>0;i-=bit1(i))
		suma+=aib[i];
	return suma;
}
