# coding: utf-8
# Your code here!
N,K = map(int,input().split())
A = [int(input()) for _ in range(N)]
dp = [[0] * N for _ in range(N)]
dp2 = [0] * N
for i in range(N):
    for j in range(i,N):
        if abs(A[i]-A[j]) <= K:
            dp[i][j] = 1
for i in range(N):
    tmax = 1
    for j in range(i+1):
        if dp[j][i]==1:
            tmax = max(tmax,dp2[j]+1)
    dp2[i] = tmax  

print(max(dp2))

