import sys
def main():
    input = sys.stdin.readline
    N, K = map(int, input().rstrip().split())
    
    BL = (300000).bit_length()
    WIDTH = pow(2, BL)
    BUFSIZE = pow(2, BL+1) - 1
    BASE = BUFSIZE - WIDTH
    
    buf = [0] * BUFSIZE
    
    def update(i, x):
        i += BASE
        buf[i] = x
        i = (i-1) // 2
        while i >= 0:
            ix2 = 2*i
            v1 = buf[ix2+1]
            v2 = buf[ix2+2]
            buf[i] = v1 if v1 > v2 else v2
            i = (i-1) // 2
    
    def _search(l, width, i, q_left, q_right):
        if q_right < l or l + width - 1 < q_left:
            return 0
        if q_left <= l and l + width - 1 <= q_right:
            return buf[i]
        nwidth = width // 2
        ix2 = i*2
        c1 = _search(l, nwidth, ix2+1, q_left, q_right)
        c2 = _search(l+nwidth, nwidth, ix2+2, q_left, q_right)
        return c1 if c1 > c2 else c2
    
    for _ in range(N):
        a = int(input().rstrip())
        maxlen = _search(0, WIDTH, 0, a-K, a+K)
        update(a, maxlen+1)
    print(_search(0, WIDTH, 0, 0, 300000))

main()
