#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, deque <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 200100;
int n, a[N], dp[N], ans, k, mn[N], mx[N];


struct RMQ {

	int n, m;
	vector <int> v;
	vector <int> rmq[20];
	vector <int> lg;

	RMQ(vector <int> v) {
		n = v.size();
		m = lg[n];
		lg.resize(1 + v.size());
		
		this->v = v;
		
		lg[1] = 0;
		for(int i = 1; i <= n; i++)
			lg[i] = 1 + lg[i / 2];
		
		rmq[0].resize(n);
		for(int i = 0; i < v.size(); i++) rmq[0][i] = i;

		for(int i = 1; i < m; i++) {
			dbg(i);
			rmq[i].resize(n);
			for(int j = 0; j + (1 << i) <= v.size(); j++) {
				rmq[i][j] = rmq[i - 1][j];
				if(v[rmq[i][j]] > v[rmq[i - 1][j + (1 << (i - 1))]])
					rmq[i][j] = rmq[i - 1][j + (1 << (i - 1))];
			}
		}
		// dbg(rmq[0]);
	}

	int getMinPos(int l, int r) {
		int i = lg[r - l + 1];
		// dbg(i);
		i--;
		int p1 = rmq[i][l];
		int p2 = rmq[i][r - (1 << i) + 1];
		if(v[p1] < v[p2]) return p1;
		return p2;
	}
} ;


struct RMQ2 {

	int n, m;
	vector <int> v;
	vector <int> rmq[20];
	vector <int> lg;

	RMQ2(vector <int> v) {
		n = v.size();
		m = lg[n];
		lg.resize(1 + v.size());
		
		this->v = v;
		
		lg[1] = 0;
		for(int i = 1; i <= n; i++)
			lg[i] = 1 + lg[i / 2];
		
		rmq[0].resize(n);
		for(int i = 0; i < v.size(); i++) rmq[0][i] = i;

		for(int i = 1; i < m; i++) {
			dbg(i);
			rmq[i].resize(n);
			for(int j = 0; j + (1 << i) <= v.size(); j++) {
				rmq[i][j] = rmq[i - 1][j];
				if(v[rmq[i][j]] < v[rmq[i - 1][j + (1 << (i - 1))]])
					rmq[i][j] = rmq[i - 1][j + (1 << (i - 1))];
			}
		}
		// dbg(rmq[0]);
	}

	int getMaxPos(int l, int r) {
		int i = lg[r - l + 1];
		// dbg(i);
		i--;
		int p1 = rmq[i][l];
		int p2 = rmq[i][r - (1 << i) + 1];
		if(v[p1] > v[p2]) return p1;
		return p2;
	}
} ;


int main() {
	ios_base::sync_with_stdio(false);

	vector <int> a;
	cin >> n >> k;
	a.resize(n + 1);
	for(int i= 1; i <= n; i++)
		cin >> a[i];

	dp[1] = 1;
	for(int i = 2; i <= n; i++)
		if(a[i] > a[i - 1])
			dp[i] = dp[i - 1] + 1;
		else dp[i] = 1;



	int ans = 1;
	// dbg_v(dp, n + 1);

	// RMQ mn(a);
	// RMQ2 mx(a);
	mn[0] = -100000;
	deque <int> mnd;
	deque <int> mxd;

	for(int i = 1; i <= k; i++) {
		// dbg(i);
		while(!mnd.empty() && a[mnd.back()] > a[i]) mnd.pop_back();
		mnd.push_back(i);
		mn[i] = mnd.front();
		
		while(!mxd.empty() && a[mxd.back()] < a[i]) mxd.pop_back();
		mxd.push_back(i);
		mx[i] = mxd.front();

	}
		// dbg(mnd);
		// dbg(mxd);

	int ok = 0;
	if(dp[k] >= k) ok++;

	for(int i = k + 1; i <= n; i++) {
		// dbg(i);
		// dbg(mn[i - 1], mx[i - 1]);
		if(mnd.front() == i - k) mnd.pop_front();
		while(!mnd.empty() && a[mnd.back()] > a[i]) mnd.pop_back();
		mnd.push_back(i);
		mn[i] = mnd.front();
		
		if(mxd.front() == i - k) mxd.pop_front();
		while(!mxd.empty() && a[mxd.back()] < a[i]) mxd.pop_back();
		mxd.push_back(i);
		mx[i] = mxd.front();
		
		// dbg(dp[i], mn[i - 1], mx[i]);
		if(dp[i] >= k)  {
			if(!ok)
				ans++, ok = 1;
		}
		else  if( !(i - k == mn[i - 1] && mx[i] == i))  {
			// dbg(i);
			ans++;
		}
		// dbg(i, dp[i], ans, mn[i], mx[i]);
	}
	cout << ans << '\n';
}	

	

Measured memory_bytes: 4224