from collections import defaultdict
n, k = map(int, input().split())
a = [int(input()) for i in range(n)]
d = defaultdict(int)
for i in range(n):
  d[a[i]] = max(d[a[i]+j] for j in range(-k, k+1)) + 1
print(max(d.values()))