#include <fstream>
#define NMax 800010
#define AMax 1000010
#define zeros(x) (( x & (x-1) ) ^ x)
using namespace std;

const char IN[]="echilibru.in",OUT[]="echilibru.out";
const int zero=(AMax-5)/2;

ifstream fin(IN);
ofstream fout(OUT);

int N,L,Rez;
int a[NMax];
int arb[AMax];

inline void Update(int x,int v)
{
	for (;x<AMax;x+=zeros(x))
		arb[x]+=v;
}

inline int Query(int x)
{
	int ret=0;
	for (;x>0;x-=zeros(x))
		ret+=arb[x];
	return ret;
}

void solve()
{
	int i;
	for (i=0;i<N;++i)
	{
		Update(zero+a[i],1);
		if (i>=2*L)
		{
			Rez+=Query(zero+a[i-L]-1)==L;
			Update(zero+a[i-2*L],-1);
		}
	}
}

int main()
{
	int i;
	fin>>N>>L;
	for (i=0;i<N;++i)
		fin>>a[i];
	fclose(stdin);

    solve();

	fout<<Rez<<"\n";
    fout.close();
	return 0;
}
