def maxLenSub(arr, n, k): 
    mls=[1 for i in range(n)] 
    max = 0

    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
                   
    for i in range(n): 
        if (max < mls[i]): 
            max = mls[i] 
      
    return max

n, k = map(int, input().split())
arr = []
for i in range(n):
    x = int(input())
    arr.append(x)


print(maxLenSub(arr, n, k))