//raja1999

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define int ll

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

//std::ios::sync_with_stdio(false);
int st[1000005],st1[1000005],a[200005];
int buildmin(int s,int e,int node){
	if(s==e){
		st[node]=a[s];
		return 0;
	}
	int mid=(s+e)/2;
	buildmin(s,mid,2*node);
	buildmin(mid+1,e,2*node+1);
	st[node]=min(st[2*node],st[2*node+1]);
	return 0;
}

int buildmax(int s,int e,int node){
	if(s==e){
		st1[node]=a[s];
		return 0;
	}
	int mid=(s+e)/2;
	buildmax(s,mid,2*node);
	buildmax(mid+1,e,2*node+1);
	st1[node]=max(st1[2*node],st1[2*node+1]);
	return 0;
}
int minseg(int s,int e,int node,int l,int r){
	if(s>r||e<l){
		return inf;
	}
	if(l<=s&&r>=e){
		return st[node];
	}
	int mid=(s+e)/2;
	return min(minseg(s,mid,2*node,l,r),minseg(mid+1,e,2*node+1,l,r));
}
int maxseg(int s,int e,int node,int l,int r){
	if(s>r||e<l){
		return 0;
	}
	if(l<=s&&r>=e){
		return st1[node];
	}
	int mid=(s+e)/2;
	return max(maxseg(s,mid,2*node,l,r),maxseg(mid+1,e,2*node+1,l,r));
}
int rt[200005],nxt[200005];
stack<int> s;
int main(){
	std::ios::sync_with_stdio(false); cin.tie(NULL);
	int t,t1;
	//cin>>t;
	t=1;
	t1=t;
	while(t--){
		int n,k,i,p,j,fl,id,ans=0;
		cin>>n>>k;
		rep(i,n){
			cin>>a[i];
		}
		rt[n-1]=1;
		fd(i,n-2,0){
			if(a[i+1]>a[i]){
				rt[i]=rt[i+1]+1;
			}
			else{
				rt[i]=1;
			}
		}
		s.push(0);
		i=1;
		while(i<n){
			if(!s.empty()){
				p=s.top();
			}
			while(!s.empty()&&a[p]>a[i]){
				nxt[p]=i;
				s.pop();
				if(!s.empty()){
					p=s.top();
				}
			}
			s.push(i);
			i++;
		}
		while(!s.empty()){
			p=s.top();
			s.pop();
			nxt[p]=n;
		}
		buildmin(0,n-1,1);
		buildmax(0,n-1,1);
		i=0;
		j=k-1;
		fl=0;
		int c=0;
		while(j<n){
			fl=0;
			if(rt[i]>=k){
				fl=2;
			}
			if(i!=0){
				id=nxt[i-1];
				id=min(j-1,id);
				//cout<<id<<" "<<rt[id+1]<<" "<<rt[id-k+1]<<endl;
				if(rt[id+1]>=j-id&&rt[id-k+1]>=j-id&&minseg(0,n-1,1,i,id)>a[i-1]&&maxseg(0,n-1,1,i,id)<a[id+1]){
					fl=1;
				}
			}
			if(fl==0){
				ans++;
			}
			if(fl==2){
				c++;
			}
			//cout<<j<<" "<<ans<<endl;
			i++;
			j++;
		}
		if(c){
			ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
} 
	

Measured memory_bytes: 9212