class SegmentTree(T)
  getter n : Int32
  getter f : T?, T? -> T?
  getter node : Array(T?)

  def initialize(v)
    initialize(v) { |a, b| a < b ? a : b }
  end

  def initialize(v, &block : T, T -> T)
    @f = ->(a : T?, b : T?) {
      a && b ? block.call(a, b) : a ? a : b ? b : nil
    }

    @n = ceil_pow2(v.size)
    @node = Array(T?).new(2 * n - 1, nil)

    v.size.times do |i|
      node[i + n - 1] = v[i]
    end

    (n - 2).downto(0) do |i|
      node[i] = f.call(node[2*i + 1], node[2*i + 2])
    end
  end

  def update(i, x)
    i += n - 1
    node[i] = x
    while i > 0
      i = (i - 1) // 2
      node[i] = f.call(node[2*i + 1], node[2*i + 2])
    end
  end

  def []=(i, x)
    update(i, x)
  end

  def get(a : Int32, b : Int32, k = 0, lo = 0, hi = -1) : T?
    hi = n if hi < 0
    case
    when hi <= a || b <= lo then nil
    when a <= lo && hi <= b then node[k]
    else
      vlo = get(a, b, 2*k + 1, lo, (lo + hi)//2)
      vhi = get(a, b, 2*k + 2, (lo + hi)//2, hi)
      f.call(vlo, vhi)
    end
  end

  def [](r : Range(Int32, Int32))
    a = r.begin
    b = r.end + (r.exclusive? ? 0 : 1)
    get(a, b)
  end

  private def ceil_pow2(n)
    1 << Math.log2(n).ceil.to_i
  end

  delegate call, to: f
end

class Problem
  getter n : Int32
  getter k : Int32
  getter a : Array(Int32)
  getter minq : SegmentTree(Int32)
  getter maxq : SegmentTree(Int32)

  def initialize(@n, @k, @a)
    maxi = Array.new(n + 1, Int32::MAX >> 1)
    @minq = SegmentTree(Int32).new(maxi) do |x, y|
      Math.min(x, y)
    end
    mini = Array.new(n + 1, Int32::MIN >> 1)
    @maxq = SegmentTree(Int32).new(mini) do |x, y|
      Math.max(x, y)
    end
  end

  def self.read
    n, k = gets.to_s.split.map { |v| v.to_i }
    a = Array.new(n) { gets.to_s.to_i }
    new(n, k, a)
  end

  def solve
    a.each do |i|
      # [lo, hi)
      lo = -1
      hi = n
      while hi - lo > 1
        mid = (lo + hi) // 2
        mini = minq[mid...hi].not_nil!
        maxi = maxq[mid...hi].not_nil!
        if mini - k <= i && i <= maxi + k
          lo = mid
        else
          hi = mid
        end
      end
      minq[lo + 1] = i
      maxq[lo + 1] = i
    end
    n.downto(0) do |i|
      if maxq[i..i] != Int32::MIN >> 1
        return i + 1
      end
    end
    return -1
  end

  def solve2
    dp = Array.new(n + 1, Int32::MAX)
    a.each do |i|
      j = dp.index { |v| (v - i).abs <= k } || -1
      dp[j + 1] = i
    end
    dp.index { |v| v == Int32::MAX }
  end

  def run
    puts solve
    # puts solve2
  end
end

Problem.read.run
