#include <bits//stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
#define ll long long
#define iloop(m, h) for (auto i = m; i != h; i += (m < h ? 1 : -1))
#define jloop(m, h) for (auto j = m; j != h; j += (m < h ? 1 : -1))
#define kloop(m, h) for (auto k = m; k != h; k += (m < h ? 1 : -1))
#define lloop(m, h) for (auto l = m; l != h; l += (m < h ? 1 : -1))
#define pll pair<ll, ll>
#define INF 1000000000000000
#define MOD1 1000000007
#define MOD2 998244353
#define MOD3 1000000009
ll n, m;
ll a[300005], dp[300005];
pll b[300005];
set<pll> st;
set<ll> lr;
ll seg[600005];
void upd(ll X, ll V) {
for (seg[X += n] = V; X > 1; X >>= 1) seg[X>>1] = max(seg[X], seg[X^1]);
}
ll qu(ll S, ll E) {
ll cans = 0;
E++;
for (S += n, E += n; S < E; S >>= 1, E >>= 1) {
if (S&1) cans = max(cans, seg[S++]);
if (E&1) cans = max(cans, seg[--E]);
}
return cans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
iloop(0, n) cin >> a[i];
iloop(0, n) b[i] = {a[i], i};
sort(b, b+n);
ll pi = 0;
st.insert({0, n-1});
lr.insert(0);
iloop(0, n) {
//cout << i << "," << b[i].second << ":" << endl;
//for (auto it : st) cout << it.first << " " << it.second << endl;
auto it = st.upper_bound({b[i].second, INF});
it--;
lr.erase((*it).first);
pll tm = *it;
st.erase(it);
if (tm.first != b[i].second) {
if (b[i].second - tm.first >= m) lr.insert(tm.first);
st.insert({tm.first, b[i].second-1});
}
if (tm.second != b[i].second) {
if (tm.second - b[i].second >= m) lr.insert(b[i].second+1);
st.insert({b[i].second+1, tm.second});
}
auto it2 = lr.upper_bound(b[i].second-m);
if (it2 != lr.begin()) {
it2--;
//cout << "qu " << *it2 + m - 1 << " " << b[i].second - 1 << endl;
dp[b[i].second] = 1 + qu(*it2 + m - 1, b[i].second - 1);
}
else {
dp[b[i].second] = 1 + qu(0, b[i].second - 1);
}
if (i < n-1 && b[i].first != b[i+1].first) {
jloop(pi, i+1) upd(b[j].second, dp[b[j].second]);
pi = i+1;
}
//cout << dp[b[i].second] << endl;
}
cout << *max_element(dp, dp+n);
}