#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long LINF = 1e18;
const int INF = 0x3f3f3f3f;
const int MAXN = 300050;
int a[MAXN], dp[MAXN];
int lg[MAXN] = {-1};
int maxn[MAXN][50];
int minn[MAXN][50];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
void create_ST(int n) {
  for (int i = 1; i <= n; i++) {
    lg[i] = lg[i / 2] + 1;
    maxn[i][0] = a[i];
    minn[i][0] = a[i];
  }
  for (int i = 1; i <= lg[n]; i++) {
    for (int j = 1; j + (1 << i) - 1 <= n; j++) {
      maxn[j][i] = max(maxn[j][i - 1], maxn[j + (1 << (i - 1))][i - 1]);
      minn[j][i] = min(minn[j][i - 1], minn[j + (1 << (i - 1))][i - 1]);
    }
  }
}
long long query_max(int l, int r) {
  int len = lg[r - l + 1];
  return max(maxn[l][len], maxn[r - (1 << (len)) + 1][len]);
}
long long query_min(int l, int r) {
  int len = lg[r - l + 1];
  return min(minn[l][len], minn[r - (1 << (len)) + 1][len]);
}
void solve(int T) {
  int n, l, r, k;
  n = read();
  k = read();
  for (int i = 1; i <= n; i++) {
    a[i] = read();
  }
  create_ST(n);
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (query_max(1, i - 1) + k < a[i] || query_min(1, i - 1) - k > a[i]) {
      dp[i] = 1;
      continue;
    }
    for (int j = 1; j < i; j++) {
      if (a[j] + k < a[i] || a[j] - k > a[i]) continue;
      dp[i] = max(dp[i], dp[j] + 1);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans = max(ans, dp[i]);
  printf("%d", ans);
}
signed main() {
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
}
