n,k = map(int, input().split())
dic = {}

for i in range(n):
  tmp = int(input())
  if i == 0:
    dic[tmp] = 1
  else:
    tmp_dict = dict(filter(lambda item: abs(item[1] - tmp) <= k, dic.items()))
    if tmp_dict == {}:
      dic[tmp] = 1
    else:
      tmp_max = max(tmp_dict.values())
      dic[tmp] = tmp_max + 1
ans = max(dic.values())
print(ans)