n,k = map(int, input().split(' '))
a = [int(input()) for i in range(n)]
maxi = 0
check = [0 for i in range(n)]
start = []
for i in range(n):
  if check[i] == 0:
    for j in range(i+1, n):
      if abs(a[i]-a[j]) <= k:
        check[j] = -1
for i in range(n):
  if check[i] != -1:
    start.append(i)
#print(check, start)
for i in range(n):
  if len(start) == 0:
    break
  if i == start[0]:
    start.pop(0)
    temp = [a[i]]
    #print(temp, i)
    for j in range(i+1, n):
      #print(start, temp, i, j)
      if abs(temp[-1]-a[j]) <= k:
        temp.append(a[j])
    #print(temp)
    maxi = max(maxi, len(temp))
  else:
    continue
print(maxi)