def main():
    import sys
    input = sys.stdin.readline

    N, K = map(int, input().split())
    A = [int(input()) for _ in range(N)]

    # N: 処理する区間の長さ
    N0 = 2**(3 * 10 ** 5).bit_length()
    e = 0
    data = [e] * (2 * N0)
    # a_k の値を x に更新

    def update(k, x):
        k += N0 - 1
        data[k] = x
        while k >= 0:
            k = (k - 1) // 2
            data[k] = max(data[2 * k + 1], data[2 * k + 2])

    # 区間[l, r)の最小値
    def query(l, r):
        L = l + N0
        R = r + N0
        s = 0
        while L < R:
            if R & 1:
                R -= 1
                s = max(s, data[R - 1])

            if L & 1:
                s = max(s, data[L - 1])
                L += 1
            L >>= 1
            R >>= 1
        return s

    for i, a in enumerate(A):
        ma = query(max(0, a - K), min(a + K, 3 * 10 ** 5 + 1))
        update(a, ma + 1)
    print(query(0, 3 * 10 ** 5 + 1) + 1)


if __name__ == '__main__':
    main()
