# -*- coding: utf-8 -*-
import numpy as np

def solve():
    N, K = map(int, input().split())
    A = np.array([int(input()) for _ in range(N)])
    dpn = np.array([1 for _ in range(N)])
    for i in range(N):
        I = np.where(np.abs(A-A[i]) <= K)
        I = I[0][I[0]>i]
        dpn[I] = np.maximum(dpn[I], dpn[i]+1)
                    
    return max(dpn)


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

