class SegTree
  attr_accessor(:node, :op, :e, :offset)
  
  def initialize(src = [], op, e)
    @op = op
    @e = e

    ofs = 1
    n = src.size
    while ofs < n
      ofs <<= 1
    end

    nd = Array.new(ofs - 1, @e)
    ofs.times do |i|
      nd << (src[i] || @e)
    end
    
    @node = nd # 0-indexed
    @offset = ofs # log2(n).ceil
    1.step(ofs - 1) do |i|
      update(-i, @e)
    end
  end

  def update(i, x) # 一点更新
    i += @offset - 1
    @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 - 1
    r += @offset - 1

    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 }
n, k = $stdin.readline.chomp.split.map(&:to_i)
a = Array.new(m + 1, 0)
seg = SegTree.new(a, chmax, 0)

res = 0
n.times do
  a = $stdin.readline.to_i
  l = [0, a - k].max
  r = [m, a + k].min
  t = seg.query(l, r + 1) + 1
  res = (res < t)? t : res
  seg.update(a, t)
end
puts res