import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import deque, defaultdict, Counter
import heapq

def main():
    N, K = MI()
    A = []
    dp = [0] * N
    dp[0] = 1
    group_list = defaultdict(int)
    group_list_ = []
    for i in range(N):
        a = I()
        A.append(a)
    for i in range(N):
        cnt = 0
        ans_list = [1]
        for j, group in enumerate(group_list_):
            if abs(group - A[i]) <= K:
                cnt = 1
                ans_list.append(group_list[group] + 1)
                group_list_[j] = A[i]
        if cnt == 0:
            group_list_.append(A[i])
        group_list[A[i]] = max(ans_list)
    ans = group_list.values()
    #print(group_list)
    print(max(ans))
if __name__ == "__main__":
    main()

