def main():
    N,K = map(int,input().split())
    A = [int(input()) for _ in range(N)]
    dp2 = [0] * N
    max0 = 0
    for i in range(N):
        tmax = 0
        for j in range(i+1):
            if -K <= (A[i]-A[j]) <= K:
                tmax = max(tmax,dp2[j]+1)
        dp2[i] = tmax  
        max0 = max(max0,tmax)
    print(max0)
main()