def maxLenSub(arr, n, k): 
    mls=[] 
    max = 0
      
    #Initialize mls[] values for all indexes 
    for i in range(n): 
        mls.append(1) 
      
    #Compute optimized maximum length subsequence 
    # values in bottom up manner 
    for i in range(n): 
        for j in range(i): 
            if (abs(arr[i] - arr[j]) <= k and mls[i] < mls[j] + 1): 
                mls[i] = mls[j] + 1
                  
    # Store maximum of all 'mls' values in 'max' 
    for i in range(n): 
        if (max < mls[i]): 
            max = mls[i] 
      
    #required maximum length subsequence 
    return max
n,k=map(int,input().split())
A = [int(input()) for i in range(n)] 
print(maxLenSub(A, n, k)) 