# -*- coding: utf-8 -*-

def solve():
    N, K = map(int, input().split())
    A = [int(input()) for _ in range(N)]
    dpn = [1 for _ in range(N)]
    for i in range(N):
        for j in range(i+1, N):
            if -K <= A[i]-A[j] <= K:
                dpn[j] = max(dpn[j], dpn[i]+1)
                    
    return max(dpn)


if __name__ == '__main__':
    print(solve())

