def make_tree(n):
    i = 2
    while True:
        if i >= n * 2:
            tree = [0] * i
            break
        else:
            i *= 2
    return tree, len(tree)

def update(i, x, tree, lt):
    i += lt // 2
    tree[i] = x
    i //= 2
    while True:
        if i == 0:
            break
        tree[i] = max(tree[2 * i], tree[2 * i + 1])
        i //= 2
    return

def find(s, t, tree, lt):
    s += lt // 2
    t += lt // 2
    ans = 0
    while True:
        if s > t:
            break
        if s % 2 == 0:
            s //= 2
        else:
            ans = max(ans, tree[s])
            s = (s + 1) // 2
        if t % 2 == 1:
            t //= 2
        else:
            ans = max(ans, tree[t])
            t = (t - 1) // 2
    return ans

n, k = map(int, input().split())
dp = [0] * n
t, lt = make_tree(300005)
for i in range(n):
    a = int(input())
    dp[i] = max(find(max(0, a - k), a, t, lt), find(a, min(300001, a + k), t, lt)) + 1
    update(a, dp[i], t, lt)
ans = dp[-1]
print(ans)