from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n,k=nii()
a=[int(input()) for i in range(n)]

def imos(n,a):
  lim=max(a)+k+1
  imos_l=[0]*lim
  for i in a:
    l=max(i-k,0)
    r=i+k-1

    imos_l[l]+=1
    if (r+1)!=lim:
      imos_l[r+1]-=1

  b=[0]
  for i in range(1,lim+1):
    b.append(imos_l[i-1]+b[i-1])

  return b

b=imos(n,a)
print(max(b))