#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll N = 1e5+5;
ll n,k,dp[N][55],a[N];
vector<int> adj[55],wth[N];
vector<int>::iterator itr;
ll solve(ll x,ll dis){
if(x>=n){
return 1;
}
if(dp[x][dis]!=-1)
return dp[x][dis];
ll mx=0;
for(ll i=0;i<wth[x].size();i++){
if(wth[x][i]==-1)
continue;
if(abs(a[x]-i)+dis<=k){
mx=max(mx,solve(wth[x][i],abs(a[x]-i)+dis)+1);
}else{
mx=max(mx,1LL);
}
}
return dp[x][dis]=mx;
}
int main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin >> n >> k;
for(int i=1;i<=n;i++){
cin >> a[i];
adj[a[i]].push_back(i);
}
for(int i=1;i<=n;i++){
for(int j=0;j<55;j++){
if((adj[j]).size()==0){
wth[i].push_back(-1);
continue;
}
itr=upper_bound(adj[j].begin(),adj[j].end(),i);
int idx;
if(itr==adj[j].end())
idx=-1;
else
idx=(*itr);
// if(idx)
wth[i].push_back(idx);
}
}
if(k==0){
cout << "1\n";
return 0;
}
memset(dp,-1,sizeof(dp));
ll ans=solve(1,0);
if(ans==0)
ans++;
cout << ans << endl;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBsb25nIGxvbmcgaW50IGxsOwoKY29uc3QgbGwgTiA9IDFlNSs1OwoKCmxsIG4sayxkcFtOXVs1NV0sYVtOXTsKdmVjdG9yPGludD4gYWRqWzU1XSx3dGhbTl07CnZlY3RvcjxpbnQ+OjppdGVyYXRvciBpdHI7CmxsIHNvbHZlKGxsIHgsbGwgZGlzKXsKCWlmKHg+PW4pewoJCXJldHVybiAxOwoJfQoKCWlmKGRwW3hdW2Rpc10hPS0xKQoJCXJldHVybiBkcFt4XVtkaXNdOwoKCWxsIG14PTA7Cglmb3IobGwgaT0wO2k8d3RoW3hdLnNpemUoKTtpKyspewoJCWlmKHd0aFt4XVtpXT09LTEpCgkJCWNvbnRpbnVlOwoJCWlmKGFicyhhW3hdLWkpK2Rpczw9ayl7CgkJCW14PW1heChteCxzb2x2ZSh3dGhbeF1baV0sYWJzKGFbeF0taSkrZGlzKSsxKTsKCQl9ZWxzZXsKCQkJbXg9bWF4KG14LDFMTCk7CgkJfQoJfQoKCXJldHVybiBkcFt4XVtkaXNdPW14Owp9CgppbnQgbWFpbigpCnsKCWlvczo6c3luY193aXRoX3N0ZGlvKGZhbHNlKSxjaW4udGllKDApLGNvdXQudGllKDApOwogICAgY2luID4+IG4gPj4gazsKICAgIAogICAgZm9yKGludCBpPTE7aTw9bjtpKyspewogICAgCWNpbiA+PiBhW2ldOwogICAgCWFkalthW2ldXS5wdXNoX2JhY2soaSk7CiAgICB9CiAgICBmb3IoaW50IGk9MTtpPD1uO2krKyl7CiAgICAJZm9yKGludCBqPTA7ajw1NTtqKyspewogICAgCQlpZigoYWRqW2pdKS5zaXplKCk9PTApewogICAgCQkJd3RoW2ldLnB1c2hfYmFjaygtMSk7CiAgICAJCQljb250aW51ZTsKICAgIAkJfQogICAgCQlpdHI9dXBwZXJfYm91bmQoYWRqW2pdLmJlZ2luKCksYWRqW2pdLmVuZCgpLGkpOwogICAgCQlpbnQgaWR4OwogICAgCQlpZihpdHI9PWFkaltqXS5lbmQoKSkKICAgIAkJCWlkeD0tMTsKICAgIAkJZWxzZQogICAgCQkJaWR4PSgqaXRyKTsKICAgIAkJLy8gaWYoaWR4KQogICAgCQl3dGhbaV0ucHVzaF9iYWNrKGlkeCk7CiAgICAJfQogICAgfQogICAgaWYoaz09MCl7CiAgICAgICAgY291dCA8PCAiMVxuIjsKICAgICAgICByZXR1cm4gMDsKICAgIH0KICAgIG1lbXNldChkcCwtMSxzaXplb2YoZHApKTsKICAgIGxsIGFucz1zb2x2ZSgxLDApOwogICAgaWYoYW5zPT0wKQogICAgICAgIGFucysrOwogICAgY291dCA8PCBhbnMgPDwgZW5kbDsKICAgIHJldHVybiAwOwp9