def longestSubseqWithDiff(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())

a = []
for i in range(n):
    a.append(int(input()))

print(longestSubseqWithDiff(a, n, k))