from collections import Counter, deque

N, K = list(map(int, input().split()))

P = list(map(int, input().split()))

ans = N - K + 1





# 変化しないものを数える

LIS = [-1] * N

LIS[-1] = 1

LIS_MIN_NOW = P[-1]

for i in reversed(list(range(N - 1))):

    p = P[i]

    if p < LIS_MIN_NOW:

        LIS_MIN_NOW = p

        LIS[i] = LIS[i + 1] + 1

    else:

        LIS_MIN_NOW = p

        LIS[i] = 1

LIS = LIS[:N - K + 1]





# スライド最小値を計算

slide_min = deque([])

MIN = []

for k in range(N):

    while slide_min and P[slide_min[-1]] >= P[k]:

        slide_min.pop()

    slide_min.append(k)



    if k < K - 1:

        continue



    if slide_min[0] + K <= k:

        slide_min.popleft()

    MIN.append(P[slide_min[0]])





# スライド最大値を計算

slide_max = deque([])

MAX = []

for k in range(N):

    while slide_max and P[slide_max[-1]] <= P[k]:

        slide_max.pop()

    slide_max.append(k)



    if k < K - 1:

        continue



    if slide_max[0] + K <= k:

        slide_max.popleft()

    MAX.append(P[slide_max[0]])





for i in range(N - K + 1):

    flg = False

    if LIS[i] >= K:

        flg = True



    if (i + 1 < N - K + 1) and (P[i] == MIN[i]) and (P[i + K] == MAX[i + 1]):

        flg = True



    ans -= flg



if len([l for l in LIS if l >= K]):

    ans += 1

print(ans)

from collections import Counter, deque

N, K = list(map(int, input().split()))

P = list(map(int, input().split()))

ans = N - K + 1





# 変化しないものを数える

LIS = [-1] * N

LIS[-1] = 1

LIS_MIN_NOW = P[-1]

for i in reversed(list(range(N - 1))):

    p = P[i]

    if p < LIS_MIN_NOW:

        LIS_MIN_NOW = p

        LIS[i] = LIS[i + 1] + 1

    else:

        LIS_MIN_NOW = p

        LIS[i] = 1

LIS = LIS[:N - K + 1]





def slide_min(A, K):

    deq, ret = deque([]), []

    for k in range(len(A)):

        while deq and A[deq[-1]] >= A[k]:

            deq.pop()

        deq.append(k)



        if k < K - 1:

            continue



        if deq[0] + K <= k:

            deq.popleft()

        ret.append(A[deq[0]])



    return ret





# スライド最小値・最大値を計算

MIN = slide_min(P, K)

MAX = list([-x for x in slide_min(list([-x for x in P]), K)])





for i in range(N - K + 1):

    flg = False

    if LIS[i] >= K:

        flg = True



    if (i + 1 < N - K + 1) and (P[i] == MIN[i]) and (P[i + K] == MAX[i + 1]):

        flg = True



    ans -= flg



if len([l for l in LIS if l >= K]):

    ans += 1

print(ans)

from collections import Counter, deque

N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
ans = N - K + 1
# 変化しないものを数える
LIS = [-1] * N
LIS[-1] = 1
LIS_MIN_NOW = P[-1]
for i in reversed(list(range(N - 1))):
    p = P[i]
    if p < LIS_MIN_NOW:
        LIS_MIN_NOW = p
        LIS[i] = LIS[i + 1] + 1
    else:
        LIS_MIN_NOW = p
        LIS[i] = 1
LIS = LIS[: N - K + 1]
# スライド最小値を計算
slide_min = deque([])
MIN = []
for k in range(N):
    while slide_min and P[slide_min[-1]] >= P[k]:
        slide_min.pop()
    slide_min.append(k)
    if k < K - 1:
        continue
    if slide_min[0] + K <= k:
        slide_min.popleft()
    MIN.append(P[slide_min[0]])
# スライド最大値を計算
slide_max = deque([])
MAX = []
for k in range(N):
    while slide_max and P[slide_max[-1]] <= P[k]:
        slide_max.pop()
    slide_max.append(k)
    if k < K - 1:
        continue
    if slide_max[0] + K <= k:
        slide_max.popleft()
    MAX.append(P[slide_max[0]])
for i in range(N - K + 1):
    flg = False
    if LIS[i] >= K:
        flg = True
    if (i + 1 < N - K + 1) and (P[i] == MIN[i]) and (P[i + K] == MAX[i + 1]):
        flg = True
    ans -= flg
if len([l for l in LIS if l >= K]):
    ans += 1
print(ans)

from collections import Counter, deque

N, K = list(map(int, input().split()))
P = list(map(int, input().split()))
ans = N - K + 1
# 変化しないものを数える
LIS = [-1] * N
LIS[-1] = 1
LIS_MIN_NOW = P[-1]
for i in reversed(list(range(N - 1))):
    p = P[i]
    if p < LIS_MIN_NOW:
        LIS_MIN_NOW = p
        LIS[i] = LIS[i + 1] + 1
    else:
        LIS_MIN_NOW = p
        LIS[i] = 1
LIS = LIS[: N - K + 1]


def slide_min(A, K):
    deq, ret = deque([]), []
    for k in range(len(A)):
        while deq and A[deq[-1]] >= A[k]:
            deq.pop()
        deq.append(k)
        if k < K - 1:
            continue
        if deq[0] + K <= k:
            deq.popleft()
        ret.append(A[deq[0]])
    return ret


# スライド最小値・最大値を計算
MIN = slide_min(P, K)
MAX = list([-x for x in slide_min(list([-x for x in P]), K)])
for i in range(N - K + 1):
    flg = False
    if LIS[i] >= K:
        flg = True
    if (i + 1 < N - K + 1) and (P[i] == MIN[i]) and (P[i + K] == MAX[i + 1]):
        flg = True
    ans -= flg
if len([l for l in LIS if l >= K]):
    ans += 1
print(ans)

-# スライド最小値を計算 -slide_min = deque([]) -MIN = [] -for k in range(N): -    while slide_min and P[slide_min[-1]] >= P[k]: -        slide_min.pop() -    slide_min.append(k) -    if k < K - 1: -        continue -    if slide_min[0] + K <= k: -        slide_min.popleft() -    MIN.append(P[slide_min[0]]) -# スライド最大値を計算 -slide_max = deque([]) -MAX = [] -for k in range(N): -    while slide_max and P[slide_max[-1]] <= P[k]: -        slide_max.pop() -    slide_max.append(k) -    if k < K - 1: -        continue -    if slide_max[0] + K <= k: -        slide_max.popleft() -    MAX.append(P[slide_max[0]]) + + +def slide_min(A, K): +    deq, ret = deque([]), [] +    for k in range(len(A)): +        while deq and A[deq[-1]] >= A[k]: +            deq.pop() +        deq.append(k) +        if k < K - 1: +            continue +        if deq[0] + K <= k: +            deq.popleft() +        ret.append(A[deq[0]]) +    return ret + + +# スライド最小値・最大値を計算 +MIN = slide_min(P, K) +MAX = list([-x for x in slide_min(list([-x for x in P]), K)])