n, k = map(int, input().split())
a = [int(input()) for i in range(n)]
b = [None for i in range(n)]
b[-1] = 1
for i in range(n-2, -1, -1):
  # Highest score selecting a[i].
  b[i] = max( (b[j] for j in range(i+1, n) if a[i]-k <= a[j] <= a[i]+k), default=0) + 1
print(max(b))