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] += UP[i+1] if P[i] < P[i+1]
}

def NextIndex(_N, _IP)
	li = (-1..(_N-2)).to_a + [-1,-1]
	ri = (1.._N).to_a + [_N,_N]
	_IP.each{|i|
		l, r = li[i], ri[i]
		li[r], ri[l] = l, r
	}
	li.pop(2)
	ri.pop(2)
	return li, ri
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
