/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>


using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
const string FILENAME = "input";
const int MAXN = 200228;


int n, k;
int p[MAXN];
int d[MAXN * 4], d1[MAXN * 4];
int ss = 1;


void change(int i, int x) {
	d[i] = x;
	while (i >> 1 > 0) {
		i >>= 1;
		d[i] = min(d[i * 2], d[i * 2 + 1]);
	}
}


int rmq(int l, int r) {
	l += ss;
	r += ss;
	int res = 1e9;
	while (l <= r) {
		if (l & 1) {
			chkmin(res, d[l]);
			l++;
		}
		if (!(r & 1)) {
			chkmin(res, d[r]);
			r--;
		}
		l >>= 1;
		r >>= 1;
	}
	return res;
}


void change1(int i, int x) {
	d1[i] = x;
	while (i >> 1 > 0) {
		i >>= 1;
		d1[i] = max(d1[i * 2], d1[i * 2 + 1]);
	}
}


int rmq1(int l, int r) {
	l += ss;
	r += ss;
	int res = -1e9;
	while (l <= r) {
		if (l & 1) {
			chkmax(res, d1[l]);
			l++;
		}
		if (!(r & 1)) {
			chkmax(res, d1[r]);
			r--;
		}
		l >>= 1;
		r >>= 1;
	}
	return res;
}



int kek[MAXN];


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//read(FILENAME);
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	while (ss < n) {
		ss <<= 1;
	}
	for (int i = 1; i <= 2 * ss; i++) {
		d[i] = 1e9;
	}
	for (int i = 0; i < n; i++) {
		change(ss + i, p[i]);
	}
	for (int i = 0; i < n; i++) {
		change1(ss + i, p[i]);
	}
	for (int i = 0; i < n - 1; i++) {
		if (p[i] > p[i + 1]) {
			kek[i]++;
		}
		if (i) {
			kek[i] += kek[i - 1];
		}
	}
	bool was = false;
	int ans = 0;
	for (int i = 0; i <= n - k; i++) {
		int t = kek[i + k - 2] - (i ? kek[i - 1]: 0);
		if (t == 0) {
			was = true;
		} else {
			bool ok = false;
			//if (i == 0 || rmq(i, i + k - 1) < p[i - 1] || p[i + k - 1] != rmq1(i, i + k - 1)) {
				if (i + k - 1 == n - 1 || rmq1(i, i + k - 1) > p[i + k] || p[i] != rmq(i, i + k - 1)) {
					ok = true;
				}
			//}
			ans += ok;
		}
	}
	if (was) {
		ans++;
	}
	cout << ans << endl;
	return 0; 	
}

Measured memory_bytes: 6912