import types
import bisect
N , K = map(int,input().split())
A = [int(input()) for _ in range(N)]
Ad = set(A)
Ad = list(Ad)
length = len(Ad)
Ad.sort()
d = [0 for k in range(max(A)+1)]
for i in range(N):
  a = A[i]
  p = bisect.bisect(Ad,a)
  for i in range(p):
    target = Ad[p-i-1]
    if abs(target - a) <= K:
      d[a] = max(d[target] + 1,d[a])
    else:
      break
  for i in range(length - p):
    target = Ad[p+i]
    if abs(target - a) <= K:
      d[a] = max(d[target]+1,d[a])
    else:
      break
print(max(d))        