
// Problem : D - Flat Subsequence
// Contest : AtCoder - ACL Beginner Contest
// URL : https://atcoder.jp/contests/abl/tasks/abl_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ff         first
#define ss         second
#define endl       '\n'
#define pb         push_back
#define int        long long
#define vi         vector<int>
#define mii        map<int, int>
#define pii        pair<int, int>
#define all(x)     (x).begin(), (x).end()
#define fill(a,b)  memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define px(a)      for(auto x: a) cout<<x<<" "; cout<<'\n';
#define pxy(a,n)   rep(i,0,n) {px(a[i])};
/*_________________________________________________________*/

const long long MOD=1e9+7,N=3e5+5;
int dp[N][N];

int find(int i,int x,int k,vi &a){
	if(dp[i][x]!=-1) return dp[i][x];
	if(i>=a.size()) return dp[i][x]=0;
	if(x==-1){
		return dp[i][x]=max(find(i+1,a[i],k,a)+1,find(i+1,x,k,a));
	}
	if(abs(a[i]-x)>k) return dp[i][x]=find(i+1,x,k,a);
	
	return dp[i][x]=max(find(i+1,a[i],k,a)+1,find(i+1,x,k,a));
}
int solve()
{
	fill(dp,-1);
	int n,k,ans=0;
	cin>>n>>k;
	vi a(n);
	rep(i,0,n) cin>>a[i];
	return find(0,-1,k,a);
}
int32_t main()
{	
	std::ios::sync_with_stdio(false); 
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<solve()<<endl;
}