// 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, cnt[N], f[N];
vector<int> vec;
struct SEGTREE {
	int n;
	vector<int> st;
	SEGTREE(int n) : n(n) {
		st.resize(n * 4 + 4, 0);
	}
	void update(int i, int l, int r, int u, int x) {
		if(l > u or r < u) return;
		if(l == r) {
			st[i] = 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]);
	}
	int get(int i, int l, int r, int u, int v) {
		if(l > v or r < u) return 0;
		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();
	}
	SEGTREE st(sz(vec));
	for(int i = 1; i <= n; i++) {
		if(i - d - 1 > 0) {
			int pre = i - d - 1;
			cnt[a[pre]]--;
			if(cnt[a[pre]] == 0) st.update(1, 1, n, a[pre], 0);
		}
		f[i] = st.get(1, 1, n, 1, a[i] - 1) + 1;
		cnt[a[i]]++;
		st.update(1, 1, n, a[i], f[i]);
	}
	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:49:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |                 freopen(task ".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:50:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |                 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... |