def longestSubseqWithDiffOne(arr, n,k): 
    dp = [1 for i in range(n)] 
 
    for i in range(n): 
        for j in range(i): 
            if (abs(arr[i]-arr[j])<=k): 
                dp[i] = max(dp[i], dp[j]+1) 
  
    result = 1   
    for i in range(n): 
        if (result < dp[i]): 
            result = dp[i] 
             
    return result 
  
n,k=map(int,input().split())
arr=[]
for i in range(n):
    arr.append(int(input()))
print(longestSubseqWithDiffOne(arr, n,k))