import sys

n,k=map(int,input().split())
a=list(map(int,sys.stdin.read().split()))

dp=[1]*(n+10)
maxp=0
checked=[0]*(n+10)
for i in range(n):
  if checked[i]==1:
    continue
  for j in range(i+1,n):
    if abs(a[i]-a[j]) <= k:
      checked[j]=1
      if dp[j] < dp[i]+1:
        dp[j]=dp[i]+1
        if maxp < dp[j]:
          maxp=dp[j]
  
print(maxp)