MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end
def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n, k = gsmi
pp = gsmi

putsend(1) if k==n

st = 1
en = k
out = pp[0]
cnt = 1
no_sort = false
sorted = pp[0..(k-1)].sort
if pp[0..(k-1)] == sorted
  no_sort=true
end
while en<n do
  ran = pp[st..(en-1)]
  max = ran.max
  min = ran.min
  if max<pp[en] && min>out
  else
    sorted = pp[st..(en)].sort
    if pp[st..(en)] == sorted
      unless no_sort
        cnt+=1
        no_sort=true
        #puts 'fa;'
      end
    else
      cnt+=1
    end
  end
  out = pp[st]
  st+=1
  en+=1
end
puts cnt
