// Author: caption_mingle
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 3e5 + 7;
int n, a[N], d, f[N], rmq[N][20], rmq2[N][20], rig[N], mnd[N];
vector<int> vec;
int get_min(int l, int r) {
	int k = __lg(r - l + 1);
	return min(rmq[l][k], rmq[r - (1 << k) + 1][k]);
}
int get_max(int l, int r) {
	int k = __lg(r - l + 1);
	return max(rmq2[l][k], rmq2[r - (1 << k) + 1][k]);
}
struct SEGTREE {
	int n;
	vector<pair<int, int>> st;
	SEGTREE(int n) : n(n) {
		st.resize(n * 4 + 4, {0, 0});
	}
	void build(int i, int l, int r) {
		if(l == r) {
			st[i].se = -l;
			return;
		}
		int m = (l + r) >> 1;
		build(i * 2, l, m);
		build(i * 2 + 1, m + 1, r);
		st[i] = max(st[i * 2], st[i * 2 + 1]);
	}
	void update(int i, int l, int r, int u, int x) {
		if(l > u or r < u) return;
		if(l == r) {
			st[i].fi = x;
			return;
		}
		int m = (l + r) >> 1;
		update(i * 2, l, m, u, x);
		update(i * 2 + 1, m + 1, r, u, x);
		st[i] = max(st[i * 2], st[i * 2 + 1]);
	}
	pair<int, int> get(int i, int l, int r, int u, int v) {
		if(l > v or r < u) return {0, -inf};
		if(u <= l and r <= v) return st[i];
		int m = (l + r) >> 1;
		return max(get(i * 2, l, m, u, v), get(i * 2 + 1, m + 1, r, u, v));
	}
};
signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	#define task ""
	if(fopen(task ".INP", "r")) {
		freopen(task ".INP", "r", stdin);
		freopen(task ".OUT", "w", stdout);
	}
	cin >> n >> d;
	for(int i = 1; i <= n; i++) cin >> a[i], vec.pb(a[i]);
	sort(all(vec));
	vec.erase(unique(all(vec)), vec.end());
	for(int i = 1; i <= n; i++) {
		a[i] = upper_bound(all(vec), a[i]) - vec.begin();
		rmq[i][0] = a[i];
	}
	for(int j = 1; (1 << j) <= n; j++) {
		for(int i = 1; i + (1 << j) - 1 <= n; i++) {
			rmq[i][j] = min(rmq[i][j - 1], rmq[i + (1 << (j - 1))][j - 1]);
		}
	}
	for(int i = d; i <= n; i++) {
		mnd[i] = get_min(i - d + 1, i);
		rmq2[i][0] = mnd[i];
	}
	for(int j = 1; (1 << j) <= n; j++) {
		for(int i = 1; i + (1 << j) - 1 <= n; i++) {
			rmq2[i][j] = max(rmq2[i][j - 1], rmq2[i + (1 << (j - 1))][j - 1]);
		}
	}
	for(int i = 1; i <= n; i++) {
		int l = i + d, r = n;
		rig[i] = n;
		while(l <= r) {
			int m = (l + r) >> 1;
			if(get_max(l, m) > a[i]) {
				r = m - 1;
				rig[i] = m;
			} else l = m + 1; 
		}
	}
	SEGTREE st(sz(vec));
	int m = sz(vec);
	for(int i = n; i > 0; i--) {
		f[i] = 1;
		for(int j = i + 1; j <= rig[i]; j++) {
			if(a[j] > a[i]) f[i] = max(f[i], f[j] + 1);
		}
	}
	cout << * max_element(f + 1, f + n + 1) << ln;
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:69:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |                 freopen(task ".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:70:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |                 freopen(task ".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |