#include <bits/stdc++.h>
using namespace std;

int a[200010];
int f1[200010][18], f2[200010][18];
int n, k;

void init() {
	for (int i = 0; i < n; i++) {
		f1[i][0] = a[i];
		f2[i][0] = a[i];
	}
	for (int j = 1; j < 18; j++) {
		for (int i = 0; i < n; i++) {
			if (i + (1 << j) - 1 >= n) continue;
			f1[i][j] = min(f1[i][j - 1], f1[i + (1 << j - 1)][j - 1]);
			f2[i][j] = max(f2[i][j - 1], f2[i + (1 << j - 1)][j - 1]);
		}
	}
}

int get_min1(int l, int r) {
	if (l > r) return 0x3f3f3f3f;
	int k = log(r - l + 1) / log(2);
	return min(f1[l][k], f1[r - (1 << k) + 1][k]);
}

int get_max(int l, int r) {
	if (l > r) return 0;
	int k = log(r - l + 1) / log(2);
	return max(f2[l][k], f2[r - (1 << k) + 1][k]);
}

int len[200010];

void merge(vector <int> &v, vector <int> &a, vector <int> &b) {
	int l = 0, r = 0;
	while (l < a.size() && r < b.size()) {
		if (a[l] < b[r]) v.push_back(a[l]), l++;
		else v.push_back(b[r]), r++;
	}
	while (l < a.size()) v.push_back(a[l]), l++;
	while (r < b.size()) v.push_back(b[r]), r++;
}

struct Segment_tree {
	vector <int> T[800010];
	void Build(int now, int l, int r) {
		if (l == r) {
//			cout << "                     add:" << l << " " << len[l] - l << endl;
			T[now].push_back(len[l] - l);
			return ;
		}
		int mid = l + r >> 1;
		Build(now << 1, l, mid), Build(now << 1 | 1, mid + 1, r);
		merge(T[now], T[now << 1], T[now << 1 | 1]);
	}
	int Query(int now, int l, int r, int L, int R, int pos) {
		if (L > R) return 0;
		if (l == L && r == R) return T[now].end() - lower_bound(T[now].begin(), T[now].end(), -pos + 1);
		int mid = l + r >> 1;
		if (R <= mid) return Query(now << 1, l, mid, L, R, pos);
		if (L > mid) return Query(now << 1 | 1, mid + 1, r, L, R, pos);
		return Query(now << 1, l, mid, L, mid, pos) + Query(now << 1 | 1, mid + 1, r, mid + 1, R, pos);
	}
}seg;

void solve2() {
	int now = n - 1;
	for (int i = n - 1; i >= k - 1; i--) {
		if (now == i) now--;
		while (now >= 0 && a[now] <= a[now + 1]) now--;
		int maxj = get_max(i - k + 1, now);
		len[i] = i - (lower_bound(a + now + 1, a + i + 1, maxj) - a) + 1;
//		cout << "i:" << i << " " << len[i] << endl;
//		cout << "  now:" << now << endl;
//		cout << "  maxj:" << maxj << endl;
//		cout << "  lower:" << lower_bound(a + now + 1, a + i, maxj) - a << endl;
//		cout << "  pos:" << i - (lower_bound(a + now + 1, a + i + 1, maxj) - a) + 1 << endl;
	}
	seg.Build(1, 0, n - 1);
}

int solve1() {
	int now = 0, ans = n - k + 1, pd = 0;
	for (int i = 0; i <= n - k; i++) {
//		cout << "i:" << i << endl;
//		cout << "  ans:" << ans << endl;
		if (now == i) now++;
		while (now < n && a[now] >= a[now - 1]) now++;
		int minj = get_min1(now, i + k - 1);
		if (minj == 0x3f3f3f3f) {
//			cout << "POS" << endl;
			if (pd) ans--;
			pd = 1;
			continue;
		}
		int pos = lower_bound(a + i, a + now, minj) - a;
//		cout << "  pos:" << pos << endl;
//		cout << "  range:" << i + k << " " << min(n - 1, pos + k - 1) << endl;
//		cout << "   sum:" << seg.Query(1, 0, n - 1, i + k, min(n - 1, pos + k - 1), i + k) << endl;
		if (seg.Query(1, 0, n - 1, i + k, min(n - 1, pos + k - 1), i + k)) ans--;
	}
	return ans;
}

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	init();
	solve2();
	printf("%d\n", solve1());
	return 0;
}


Measured memory_bytes: 76152