import sys
input=sys.stdin.readline

def main(args):
    n, k = map(int,input().split())
    
    A = []
    for i in range(n):
        a = int(input())
        A.append(a)
    
    dp = [1]*n
    ans = 0
    
    for i in range(n):
        for j in range(i):
            if abs(A[i]-A[j]) <= k and dp[i] < dp[j] + 1:
                dp[i] = dp[j] + 1
    
    for i in range(n):
        if ans < dp[i]:
            ans = dp[i]
            
    print(ans)
    
if __name__ == '__main__':
    main(sys.argv[1:])