class BIT:
    def __init__(self,N):
        self.N=N
        self.bit=[0]*N
    def add(self,a,w):
        x=a
        while(x<self.N):
            self.bit[x]+=w
            x|=x+1
    def get(self,a):
        ret,x=0,a-1
        while(x>=0):
            ret+=self.bit[x]
            x=(x&(x+1))-1
        return ret
    def cum(self,l,r):
        return self.get(r)-self.get(l) 

N,K=map(int,input().split())
A=[int(input()) for i in range(N)]
M=max(A)
bit=BIT(M+1)
ans=0

for i in range(N):
    bit.add(A[i],1)
for R in range(M+1):
    l=max(0,R-K)
    res=bit.cum(l,R+1)
    ans=max(ans,res)
print(ans)