class SegmentTree
  attr_accessor(:node, :op, :e, :offset)
  
  def initialize(n, op, e)
    @op = op
    @e = e

    ofs = 1
    while ofs < n
      ofs <<= 1
    end
    
    @node = Array.new((ofs << 1) - 1, @e) # 0-indexed
    @offset = ofs - 1 # log2(n).ceil - 1
  end

  def update(i, x) # 一点更新
    i += @offset
    @node[i] = x
    
    while i > 0
      i = (i - 1) >> 1
      @node[i] = @op.call(@node[(i << 1) + 1], @node[(i << 1) + 2])
    end
  end

  def query(l, r) # [l, r)
    l += @offset
    r += @offset

    res = @e
    while l < r
      if l & 1 == 0
        res = @op.call(res, @node[l])
      end
      if r & 1 == 0
        res = @op.call(res, @node[r - 1])
      end
      l = l >> 1
      r = (r - 1) >> 1
    end
    return res
  end
end

m = 3 * (10 ** 5)
chmax = -> (x, y) { (x > y)? x : y }
chmin = -> (x, y) { (x < y)? x : y }
n, k = $stdin.readline.chomp.split.map(&:to_i)
a = Array.new(n) { $stdin.readline.to_i }
seg = SegmentTree.new(m + 1, chmax, 0)

res = 0
a.each do |x|
  v = seg.query(chmax.call(x - k, 0), chmin.call(x + k, m) + 1) + 1
  res = chmax.call(res, v)
  seg.update(x, v)
end
puts res