N, K = gets.split.map(&:to_i)
P = gets.split.map(&:to_i)

IP = [nil]*N
N.times{|i|
	IP[P[i]] = i
}

UP = [1]*N
(N-2).downto(0){|i|
	UP[i] = P[i] < P[i+1] ? UP[i+1]+1 : 1
}

def NextIndex(_N, _IP)
	ri = (1..N).to_a + [N, N]
	li = (-1..(N-2)).to_a + [-1, -1]
	lr, rr = [nil]*N, [nil]*N
	_IP.each{|i|
		l, r = li[i], ri[i]
		li[r], ri[l] = l, r
		lr[i], rr[i] = l, r
	}
	return lr, rr
end

LU,_ = NextIndex(N, IP)
_,RL = NextIndex(N, IP.reverse)

pm, n = K <= UP[0] ? [1, 0] : [0, 1]
(N-K).times{|i|
	if K <= UP[i+1]
		pm += 1
	elsif RL[i] < i+K or i < LU[i+K]
		n += 1
	end
}

p n+[pm,1].min
