from functools import lru_cache
import sys
sys.setrecursionlimit(30000)

@lru_cache(maxsize=30000)
def subsolve(i):
    a = As[i]
    l=None
    r=None
    for j in range(i, 0, -1):
        if a-k <= As[j-1] <= a and l==None:
            l = subsolve(j-1)+1
        if a < As[j-1] <= a+k and r==None:
            r = subsolve(j-1)+1
        if l!=None and r!=None: break
    if l==None: l=1
    if r==None: r=1
    return max(l,r)

def solve(n, k, xs):
    return max(subsolve(i) for i in range(n))

if __name__ == "__main__":
    n, k = map(int, input().split())
    *As, = [int(input()) for _ in range(n)]
    print(solve(n, k, As))