import sys

# 許容する再帰処理の回数を変更
sys.setrecursionlimit(10 ** 5 + 10)

def rec(pos, a, dp, n, k):
    if dp[pos] != -1:
        return dp[pos]
    dp[pos] = 1
    for nxt in range(pos + 1, n):
        if abs(a[pos] - a[nxt]) <= k:
            dp[pos] = max(dp[pos], rec(nxt, a, dp, n, k) + 1)
    return dp[pos]


def acl_beginner_d():
    n, k = map(int, input().split())
    a = []
    for _ in range(n):
        a.append(int(input()))
    dp = [-1] * n
    ans = 0
    for i in range(n-1, -1, -1):
        v = rec(i, a, dp, n, k)
        ans = max(ans, v)
    print(ans)


acl_beginner_d()