#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

template<class T>
struct segtree{//monoid
	ll n;//葉の数
	T e;//単位元(RMQなら,MAXなど)
	vector<T> nodes;
	function<T(T,T)> func;//monoid

	segtree(vector<T> _v,T _e,function<T(T,T)> _f){//segtree<int> seg(,..);みたいに
		init(_v,_e,_f);
	}

	void set(){//set tree
		for(ll i = n-2;i>=0;i--){
			nodes[i] = func(nodes[i*2+1],nodes[i*2+2]);
		}
	}

	void init(vector<T> _v,T _e,function<T(T,T)> _f){
		e = _e; func = _f;
		ll _n = _v.size();
		n = 1;
		while(_n>n)n*=2;
		n*=2;//葉の数
		nodes.resize(2*n-1);
		rep(i,n){//init
			if(i<_v.size())nodes[n-1+i]=_v[i];
			else nodes[n-1+i] = e;
		}
		set();
	}
	void update(ll id,ll num){//[lef,rig)
		id += n-1;
		nodes[id] = num;
		while(1){
			ll par = (id-1)/2;
			nodes[par] = func(nodes[par*2+1],nodes[par*2+2]);
			id = par;
			if(id==0)break;
		}
	}
	T get(ll lef,ll rig,ll a,ll b,ll id){//元は[lef,rig)で,今は[a,b)
		if(rig<=a || b <= lef){//被り無し
			return e;//単位元を返す
		}else if(lef<=a && b<=rig){//完全被覆
			return nodes[id];
		}else{//交差してる
			return func(get(lef,rig,a,a+(b-a)/2,id*2+1), get(lef,rig,a+(b-a)/2,b,id*2+2) );
		}
	}
	T get(ll left,ll right){//値の取得,[left,right)
		return get(left,right,0,n,0);
	}

	T operator[](ll id){//要素アクセス
		return nodes[id+n-1];
	}
};

ll n,k;
Vi p;
Vi v;

bool ck(ll lef,ll rig){
	rig -= 1;
	ll tp = v[rig]-v[lef];
	if(tp==rig-lef && v[lef]!=0){
		return true;
	}else{
		return false;
	}
}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	std::cout<<std::fixed<<std::setprecision(30);
	cin>>n>>k;
	p.resize(n);
	v.resize(n);
	rep(i,n){
		cin>>p[i];
	}
	rep(i,n-1){
		if(p[i]<p[i+1]){
			if(i!=0)v[i]+= v[i-1]+1;
			else v[i] += 1;
		}else{
			v[i] = 0;
		}
	}
	ll ans = 0;
	segtree<ll> sg(p,0,[](ll x,ll y){return max(x,y);});
	segtree<ll> smin(p,INF,[](ll x,ll y){return min(x,y);});
	ll nochange = 0;
	rep(i,n){
		if(i+k-1>=p.size())break;
		ll idn = i+k-1;
		if(ck(i,idn)){
			if(nochange==0){
				nochange=1;
				ans++;
				continue;
			}else{
				continue;
			}
		}
		if(p[idn]>=sg.get(i,idn)){
			if(i!=0 && p[i-1]<=smin.get(i,idn)){
				//no act
			}else{
				ans++;
			}
		}else{
			ans++;
		}
	}
	print(ans);
	return 0;
}

Measured memory_bytes: 22856