#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];
	}
};

struct minseg{
	vector<vector<int>> t;
	vector<int> g;
	
	minseg(vector<int> v){
		int n = v.size();
		t = {v};
		for(int k=1,p2=2; p2<=n; ++k,p2*=2){
			vector<int> s;
			auto &pr = t.back();
			for(int i=0;i+p2<=n;++i){
				int val = min(pr[i], pr[i+p2/2]);
				s.push_back(val);
			}
			t.push_back(s);
		}
		g.assign(n+1, 0);
		for(int i=2;i<=n;++i) g[i] = g[i/2]+1;
	}
	int getmin(int l, int r){
		int k = g[r-l+1];
		return min(t[k][l], t[k][r-(1<<k)+1]);
	}
};

struct maxseg{
	vector<vector<int>> t;
	vector<int> g;
	
	maxseg(vector<int> v){
		int n = v.size();
		t = {v};
		for(int k=1,p2=2; (1<<k)<=n; ++k,p2*=2){
			vector<int> s;
			auto &pr = t.back();
			for(int i=0;i+p2<=n;++i){
				int val = max(pr[i], pr[i+p2/2]);
				s.push_back(val);
			}
			t.push_back(s);
		}
		g.assign(n+1, 0);
		for(int i=2;i<=n;++i) g[i] = g[i/2]+1;
	}
	int getmax(int l, int r){
		int k = g[r-l+1];
		return max(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);
	minseg tmn(a);
	maxseg tmx(a);
	
	
	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.getmin(j,i+k-1);
		int y = tmx.getmax(i,j-1);
		if(x < y) return -1;
		if(tsum.getsum(i+1,j-1)!=0) return -1;
		
		x = tmx.getmax(j,i+k-1);
		y = tmn.getmin(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: 34260