#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 200100

void build(ll* a,ll* tree,ll ti,ll l,ll r){
	if(l==r){
		tree[ti]=a[l];
		return;
	}
	ll mid = (l+r)/2;
	build(a,tree,2*ti,l,mid);
	build(a,tree,2*ti+1,mid+1,r);
	tree[ti] = max(tree[2*ti],tree[2*ti+1]);
}

ll query(ll* tree,ll ti,ll l,ll r,ll left,ll right){
	if(left==-1 || right==-1) return -1;
	if(l>=left && r<=right) return tree[ti];
	if(l>right || r<left) return -1;
	ll mid = (l+r)/2;
	ll first = query(tree,2*ti,l,mid,left,right);
	ll second = query(tree,2*ti+1,mid+1,r,left,right);
	return max(first,second);
}
ll tree1[4*MAX];
void build2(ll* a,ll* tree,ll ti,ll l,ll r){
	if(l==r){
		tree[ti]=a[l];
		return;
	}
	ll mid = (l+r)/2;
	build2(a,tree,2*ti,l,mid);
	build2(a,tree,2*ti+1,mid+1,r);
	tree[ti] = min(tree[2*ti],tree[2*ti+1]);
}

ll query2(ll* tree,ll ti,ll l,ll r,ll left,ll right){
	if(left==-1 || right==-1) return 1e9;
	if(l>=left && r<=right) return tree[ti];
	if(l>right || r<left) return 1e9;
	ll mid = (l+r)/2;
	ll first = query2(tree,2*ti,l,mid,left,right);
	ll second = query2(tree,2*ti+1,mid+1,r,left,right);
	return min(first,second);
}
ll tree2[4*MAX];

ll get_min(ll l,ll r,ll n){
	return query2(tree2,1,0,n-1,l,r);
}
ll get_max(ll l,ll r,ll n){
	return query(tree1,1,0,n-1,l,r);
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll n,k;cin>>n>>k;
	ll a[n];For(i,0,n) cin>>a[i];
	build(a,tree1,1,0,n-1);
	build2(a,tree2,1,0,n-1);

	bool once = 0;

	ll inversions = 0 , ans = 0;
	For(i,1,k) if(a[i]<a[i-1]) inversions++;

	if(inversions!=0) ans++;
	else once = 1;

	For(j,k,n){
		ll i = j-k;
		if(a[i]>a[i+1]) inversions--;
		if(a[j]<a[j-1]) inversions++;
		if(inversions==0) {
			once = 1;
			continue;
		}

		ll maxi = get_max(i+1,j-1,n);
		if(a[j]<maxi){
			ans++;
			continue;
		}
		ll mini = get_min(i+1,j-1,n);
		if(a[i]>mini){
			ans++;
			continue;
		}
	}
	if(once) ans++;
	cout<<ans<<endl;



























	
}

Measured memory_bytes: 14080