#include <bits/stdc++.h>
//#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (int) (k); ++i)
#define Rep(i, j, k) for(R int i = (j); i >= (int) (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 200011;
const ll INF = 5e16;
const ll P = 998244353;

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread(buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		R ll x = 0; R int f = 0; R char dd;
		for (; !isdigit(ch); dd) f ^= (ch == '-');
		for (; isdigit(ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) x = -x, putchar('-');
		if (x > 9) write(x / 10); putchar(x % 10 | 48);
	}

	inline void wrn ( ll x ) { write(x), putchar(' '); }

	inline void wln ( ll x ) { write(x), putchar('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x), wln(y); }

}

using IO::wln;
using IO::read;

namespace Cesare {
	
	/*
		i - i + k - 1 -> i + 1 - i + k
		a[i] = min[i][i + k - 1]
		a[i + k] > max[i][i + k - 1]
	*/
	
	ll n, k, F, Ans, Limit = 1, a[N], V[N];
	
	#define ls(x) (x << 1)
	#define rs(x) (x << 1 | 1)
	#define mid ((l + r) >> 1)
	
	ll Mn[N << 2], T[N << 2];
	
	inline void pushUp ( ll p ) { 
		T[p] = max(T[ls(p)], T[rs(p)]); 
		Mn[p] = min(Mn[ls(p)], Mn[rs(p)]);
	}
	
	inline void build ( ll p, ll l, ll r ) {
		if (l == r) return (void) (Mn[p] = T[p] = a[l]);
		build(ls(p), l, mid); build(rs(p), mid + 1, r); pushUp(p);
	}
	
	inline ll QueryMax ( ll p, ll l, ll r, ll ul, ll ur, ll res = 0 ) {
		if (l >= ul && r <= ur) return T[p];
		if (mid >= ul) res = max(res, QueryMax(ls(p), l, mid, ul, ur));
		if (mid < ur)  res = max(res, QueryMax(rs(p), mid + 1, r, ul, ur));
		return res;
	}
	
	inline ll QueryMin ( ll p, ll l, ll r, ll ul, ll ur, ll res = INF ) {
		if (l >= ul && r <= ur) return Mn[p];
		if (mid >= ul) res = min(res, QueryMin(ls(p), l, mid, ul, ur));
		if (mid < ur)  res = min(res, QueryMin(rs(p), mid + 1, r, ul, ur));
		return res;
	}
	
	int main() {
		Set (Mn, 0x3f); 
		n = read(), k = read();
		For ( i, 1, n ) a[i] = read();
		
		build(1, 1, n);
		
//		Rep ( i, k, 2 ) 
//			if (a[i] > a[i - 1]) ++Limit;
//			else break; 
		int now = 0;
		For ( i, 1, k - 1 ) 
			now += a[i] < a[i + 1];
		for (int i = 1, j = k; j <= n; ++i, ++j) {
			if (now == k - 1) Ans = V[i] = 1;
			now -= a[i] < a[i + 1], now += a[j] < a[j + 1];
		}
//		For ( i, 1, n - k + 1 ) {
//			ll Mn = QueryMin(1, i, i + k - 2, 1, n);
//			ll Mx = QueryMax(1, i, i + k - 2, 1, n);
//			Limit = (a[i] == Mn && a[i + k] > Mx)? Limit + 1: 1;
//			V[i] = Limit >= k;
//		} 
		for (int i = 1, j = k; j <= n; ++i, ++j) {
			if (V[i]) continue;
			if (i == 1) {++Ans; continue;}
			ll Mn = QueryMin(1, 1, n, i, j - 1);
			ll Mx = QueryMax(1, 1, n, i, j - 1);
			if (a[i - 1] < Mn && a[j] > Mx) continue;
			else ++Ans;
		} return wln(Ans), 0;
	}
	
}

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);

	return Cesare :: main();
}

/*

*/






Measured memory_bytes: 15872