def segfunc(x, y): return max(x, y)

def init(arr):
    global node
    size = len(arr)
    n = 2 ** (size - 1).bit_length()
    node = [0] * 2 * n
    for i in range(size):
        node[i + n - 1] = arr[i]
    for i in reversed(range(n - 2)):
        node[i] = segfunc(node[i*2+1], node[i*2+2])

def update(i, x):
    i += noden-1
    node[i] = x
    while i:
        i = (i-1)//2
        node[i] = segfunc(node[i*2+1], node[i*2+2])

def query(l, r):
    L = l + noden
    R = r + noden
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = segfunc(s, node[R - 1])
        if L & 1:
            s = segfunc(s, node[L - 1])
            L += 1
        L >>= 1
        R >>= 1
    return s

N, K = map(int, input().split())
MAX_N = 2**(N-1).bit_length()
node = []
noden = MAX_N
init([0] * 30005)
INF = 0
ma = 30005
ans = 0
for i in range(N):
    a = int(input())
    tmp = query(max(a - K, 0), min(ma, a + K) + 1)
    update(a, tmp + 1)
    ans = max(ans, tmp + 1)
print(ans)
