# テストケース通る気がしない! n = gets.to_i l = gets.to_i if n == 1 then puts 0 exit end def juushin(xs) sum = 0 cnt = 0 xs.each do |x, c| sum += x * c cnt += c end return sum / cnt.to_f + 0.5 end xs = $stdin.read.split.map(&:to_i).reverse xs << 0 ws = Hash.new{0} ans = 0 for i in 0...xs.size do if i > 0 then if (xs[i-1] - xs[i]).abs >= l then puts -1 exit end j = juushin(ws) ok = (xs[i-1] < j) && (j < xs[i-1] + l) && (xs[i] < j) && (j < xs[i] + l) ans += 1 unless ok end l.times do |o| ws[xs[i] + o] += 1 end end puts ans