import math

N, K = map(int, input().split())
Amax = 300000
# seg_leaf : seg_tree の葉で [0:0} に当たるノードのインデックス
seg_leaf_0 = 2**int(math.log2(Amax+1))
# seg_tree : 1-indexed のセグ木
seg_tree = [0]*(seg_leaf_0 * 2)

def get_max(check_min, check_max, area_min, area_max, node_ind):
    if area_max < check_min or check_max < area_min:
        return 0
    elif check_min <= area_min or area_max < check_max:
        return seg_tree[node_ind]
    else:
        v1 = get_max(check_min, check_max, area_min, (area_min + area_max)//2, node_ind * 2)
        v2 = get_max(check_min, check_max, (area_min + area_max)//2 + 1, area_max, node_ind * 2 + 1)
        return(max(v1, v2))

def update(node_ind, value):
    seg_tree[node_ind] = value
    if node_ind != 1:
        update(node_ind//2, value)

for _ in range(N):
    A = int(input())
    x = get_max(max(A-K, 0), min(A+K, Amax), 0, seg_leaf_0 * 2 - 1, 1)
    update(seg_leaf_0 + A, x + 1)

print(seg_tree[1])