import numpy as np
N, K = list(map(int, input().split()))
dp = np.ones((N+1, 300000)) * -1

for i in range(N):
    A = int(input())
    if dp[i, A] < 0:
        dp[i, A] = 0
    for j in np.where(dp[i,:] > -1)[0]:
        if dp[i+1, j] < 0:
            dp[i+1, j] = dp[i, j]
        if (abs(A - j) <= K) and (dp[i+1, A] < (dp[i, j] + 1)):
            dp[i+1, A] = dp[i, j] + 1
print(int(np.max(dp[N])))