import sys
input = sys.stdin.readline
from itertools import accumulate
N,K = map(int,input().split())
A = [int(input()) for i in range(N)]

d = [0] * 600010
d[A[0]] = 1
d[A[0]+1] = -1

for a in A[1:-1]:
    d[max(a-K,0)] += 1
    d[a+K+1] += -1

d[A[-1]] += 1
d[A[-1]+1] += -1
e = accumulate(d)

print(max(e))



