import math
from collections import deque

def getval():
    n,k = map(int,input().split())
    a = [int(input()) for i in range(n)]
    return n,k,a 

def main(n,k,a):
    t = [0 for i in range(2**20+1)]
    ans = 0
    for i in range(n):
        cur = a[i]
        floor = max(1,cur-k)
        ceil = min(cur+k,2**19)
        q = deque([1])
        temp = 1
        #print(cur,floor,ceil)
        while q:
            idx = q.pop()
            h = math.floor(math.log2(idx))
            curfloor = (idx-2**h) * 2**(19-h) + 1
            curceil = (idx-2**h+1) * 2**(19-h)
            nextceil = ((idx*2)-2**(h+1)+1) * 2**(19-(h+1))
            nextfloor = nextceil + 1
            #print(h,idx)
            #print(idx,curfloor,curceil,nextfloor,nextceil)
            if curfloor>=floor and curceil<=ceil:
                if temp<t[idx]+1:
                    temp = t[idx] + 1
                continue
            if nextceil>=floor and h<19:
                q.append(idx*2)
            if nextfloor<=ceil and h<19:
                q.append(idx*2+1)
            #t[idx] = max(t[idx],temp)
        idx = 1
        for h in range(20):
            t[idx] = max(t[idx],temp)
            idx *= 2
            nextceil = ((idx)-2**(h+1)+1) * 2**(19-(h+1))
            #print(nextceil)
            if cur>nextceil:
                idx += 1
    print(t[1])
        #print(t[2**19+2])
        

if __name__=="__main__":
    n,k,a = getval()
    main(n,k,a) 