N, K = map(int, input().split())
M = 300000
P = {}
for i in range(N):
  a = int(input())
  c = 0
  for j in range(max(a - K, 0), min(a + K + 1, M + 1)):
    c = max(P.get(j, 0), c)
  P[a] = max(P.get(a, 0), c + 1)
p = list(P.values())
print(max(p))