N, K = map(int, input().split())
dp = [0 for i in range(N)]
A = []
for i in range(N):
  A.append(int(input()))
  c = 1
  for j in range(i):
    if - K <= A[i] - A[j] <= K:
      c = max(c, dp[j] + 1)
  dp[i] = c
print(dp[-1])