N,K = gets.split.map(&:to_i)
P = gets.split.map(&:to_i)
remp = []
count = 0
count2 = 0

(N - K + 1).times do |i|
  tmp = i + K - 1
  p = Marshal.load(Marshal.dump(P))
  p[i..tmp] = p[i..tmp].sort! 
  if P == p
    count2 += 1
  end
  if P != p && remp != p
    count += 1
    remp = Marshal.load(Marshal.dump(p))
  end
end

puts count2 > 0 ? count + 1 : count