#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;

ll brute(vector<int> a, int k){
	set<vector<int>> u;
	for(int i=0;i+k<=a.size();++i){
		auto v = a;
		sort(v.begin()+i, v.begin()+i+k);
		//if(u.count(v)) cout<<"!"<<endl;
		//for(int x : v) cout<<x<<' '; cout<<endl;
		u.insert(v);
	}
	return u.size();
}


struct sumseg{
	vector<int> a;
	vector<ll> p;
	sumseg(vector<int> v){
		a = v;
		int n = v.size();
		p.assign(n+1, 0);
		for(int i=n-1;i>=0;--i) p[i] = p[i+1] + a[i];
	}
	ll getsum(int l, int r){
		return p[l] - p[r+1];
	}
};

template<class T>
struct sparse_table{
	vector<vector<T>> t;
	vector<int8_t> g;
	
	function<T(const T &x, const T &y)> f;
	
	sparse_table(vector<T> v, auto func) : f(func){
		int n = v.size();
		t = {v};
		for(int k=1,p=1; (1<<k)<=n; ++k,p<<=1){
			t.emplace_back();
			for(int i=0;i+p*2<=n;++i) t.back().push_back(f(t[k-1][i], t[k-1][i+p]));
		}
		g.assign(n+1, 0);
		for(int i=2;i<=n;++i) g[i] = g[i/2]+1;
	}
	T operator()(int l, int r){
		int k = g[r-l+1];
		return f(t[k][l], t[k][r-(1<<k)+1]);
	}
};

ll solve(vector<int> a, int k){
	int n = a.size();
	vector<int> v;
	for(int i=0;i+k<=n;++i) v.push_back(i);
	
	vector<int> b(n);
	for(int i=1;i<n;++i) b[i] = (a[i]<a[i-1]);
	
	sumseg tsum(b);
	sparse_table<int> tmn(a, [](int x, int y){return min(x,y);});
	sparse_table<int> tmx(a, [](int x, int y){return max(x,y);});
	
	
	std::function<int(int,int)> cmp;
	cmp = [&](int i, int j){
		//cerr<<"cmp "<<i<<' '<<j<<endl;
		if(i==j) return 0;
		if(i>j) return -cmp(j,i);
		if(i+k<=j){
			if(tsum.getsum(i+1,i+k-1)!=0) return -1;
			if(tsum.getsum(j+1,j+k-1)!=0) return +1;
			return 0;
		}
		int x = tmn(j,i+k-1);
		int y = tmx(i,j-1);
		if(x < y) return -1;
		if(tsum.getsum(i+1,j-1)!=0) return -1;
		
		x = tmx(j,i+k-1);
		y = tmn(i+k,j+k-1);
		if(y < x) return +1;
		
		if(tsum.getsum(i+k+1,j+k-1)!=0) return +1;
		
		return 0;
	};
	
	//cout<<"?"<<cmp(1,2)<<endl; return 0;
	
	
	sort(v.begin(), v.end(), [&](int i, int j){
		return cmp(i,j)==-1;
	});
	
	int ans = 1;
	for(int i=1;i<v.size();++i){
		int c = cmp(v[i-1], v[i]);
		assert(c<=0);
		if(c<0) ++ans;
	}
	return ans;
}


int main(){
	//freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
	mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
	
	
	if(0){
		for(;;){
			int n = rnd()%50 + 2;
			int k = rnd()%(n-1) + 2;
			
				
			
			vector<int> a(n);
			for(int i=0;i<n;++i) a[i] = i;
			shuffle(ALL(a), rnd);
		
				cout<<n<<' '<<k<<endl;
				for(int x : a) cout<<x<<' '; cout<<endl;
				cout<<endl;
		
			int res = solve(a, k);
			int ans = brute(a, k);
			if(res!=ans){
				cout<<n<<' '<<k<<endl;
				for(int x : a) cout<<x<<' '; cout<<endl;
				cout<<ans<<' '<<res<<endl;
			}
			assert(ans==res);
		}
	}
	
	bool gen = false;
	
	int n,k;
	if(gen){
		n = 10;
		k = 4;
	}else cin>>n>>k;
	
	vector<int> a(n);
	
	if(gen){
		for(int i=0;i<n;++i) a[i] = i;
		shuffle(ALL(a), rnd);
		
		for(int x : a) cout<<x<<' '; cout<<endl;
	}else{
		for(auto &_ : a) cin>>_;
	}
	
	//cerr<<brute(a,k)<<endl;
	cout<<solve(a,k)<<endl;
	
	
	return 0;
}


Measured memory_bytes: 34276