#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <atcoder/segtree>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;
using namespace atcoder;

int dp[300001];

int op(int a, int b) {
    return max(a, b);
}
int e() {
    return 0;
}

int main()
{
	int n,k;cin>>n>>k;
	segtree<int , op, e> seg(300001);
  
	vector<int> vec;
	
	for(int i = 0;i<n;i++)
	{
		int x;s(x);
		vec.push_back(x);	
	}
	int maxi = 0;
 
	for(int i = n-1;i>=0;i--)
	{
		int low = max(0 , vec[i]-k);
		int high = min(300000 , vec[i] + k);
		
		int maxi = seg.prod(low,high+1);
		
		dp[i] = 1 + maxi;
		maxi = max(maxi , dp[i]);
      	seg.set(vec[i],dp[i]);
	}
	
	
	cout<<maxi<<endl;
	
	
	return 0;
}