#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <atcoder/all>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define PI 3.14159265359
using namespace std;
using namespace atcoder;
using mint = modint998244353;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int MOD = 1e9+7;
const int MODD = 998244353;
const ll LLINF = 1e18;

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

int e() { return -1; }

segtree<int, op, e> seg(300001);
int dp[300001];

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	dp[0] = 1;
	seg.set(1, 1);
	for (int i = 1; i < n; i++){
		dp[i] = max(1, seg.prod(max(0, a[i]-k), min(n, a[i]+k+1))+1);
		seg.set(a[i], dp[i]);
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
		ans = max(ans, dp[i]);
	cout << ans << endl;
	return 0;
}
