n, k = list(map(int, input().split()))

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



from collections import deque

def slide_max(k, l):

    rs = []

    dq = deque()

    for i, x in enumerate(l):

        while True:

            if not len(dq):

                dq.append(i)

                break

            lxi = dq[-1]

            if x < l[lxi]:

                dq.append(i)

                break

            dq.pop()

        if i+1 < k:

            continue

        sxi = dq[0]

        rs.append(l[sxi])

        if sxi == (i + 1 - k):

            dq.popleft()

    return rs



def slide_min(k, l):

    rs = []

    dq = deque()

    for i, x in enumerate(l):

        while True:

            if not len(dq):

                dq.append(i)

                break

            lxi = dq[-1]

            if x > l[lxi]:

                dq.append(i)

                break

            dq.pop()

        if i+1 < k:

            continue

        sxi = dq[0]

        rs.append(l[sxi])

        if sxi == (i + 1 - k):

            dq.popleft()

    return rs



maxs, mins = slide_max(k, xs), slide_min(k, xs)

aa, bb = xs[:k], xs[k:]



b, nb, bx = aa[0], aa[1], aa[-1]

ba = None

c = 1

for a in aa:

    if ba == None:

        ba = a

        continue

    if a > ba:

        c += 1

    else:

        c = 1

    ba = a



rok = False

if c == k:

    rok = True



r = 1

bs = xs[0]

for i, (s, x) in enumerate(zip(xs[1:], bb)):



    if x > bx:

        c = min(c+1, k)

    else:

        c = 1

    bx = x



    if c == k:

        if not rok:

            r += 1

        rok = True

        continue



    if x != maxs[i+1]: 

        r+=1

    elif bs != mins[i]:

        r+=1

    bs = s



print(r)

n, k = list(map(int, input().split()))

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

from collections import deque

def slide_max(k, l):

    rs, rrs = [], set()

    dq = deque()

    for i, x in enumerate(l):

        while True:

            if not len(dq):

                dq.append(i)

                break

            lxi = dq[-1]

            if x < l[lxi]:

                dq.append(i)

                break

            dq.pop()

        if i+1 < k:

            continue

        sxi = dq[0]

        rs.append(l[sxi])

        if sxi == (i + 1 - k):

            dq.popleft()

    return rs



def slide_min(k, l):

    rs = []

    rrs = set()

    dq = deque()

    for i, x in enumerate(l):

        while True:

            if not len(dq):

                dq.append(i)

                break

            lxi = dq[-1]

            if x > l[lxi]:

                dq.append(i)

                break

            dq.pop()

        if i+1 < k:

            continue

        if len(dq) == k:

            rrs.add(i+1-k)

        sxi = dq[0]

        rs.append(l[sxi])

        if sxi == (i + 1 - k):

            dq.popleft()

    return rs, rrs



maxs, (mins, ns) = slide_max(k, xs), slide_min(k, xs)

r = 1

for i, (s, x) in enumerate(zip(xs, xs[k:])):

    if (x != maxs[i+1] or s != mins[i]) and (i+1 not in ns): 

        r+=1

if (0 not in ns) and (len(ns) > 0):

    r += 1

print(r)

n, k = list(map(int, input().split()))
xs = list(map(int, input().split()))
from collections import deque


def slide_max(k, l):
    rs = []
    dq = deque()
    for i, x in enumerate(l):
        while True:
            if not len(dq):
                dq.append(i)
                break
            lxi = dq[-1]
            if x < l[lxi]:
                dq.append(i)
                break
            dq.pop()
        if i + 1 < k:
            continue
        sxi = dq[0]
        rs.append(l[sxi])
        if sxi == (i + 1 - k):
            dq.popleft()
    return rs


def slide_min(k, l):
    rs = []
    dq = deque()
    for i, x in enumerate(l):
        while True:
            if not len(dq):
                dq.append(i)
                break
            lxi = dq[-1]
            if x > l[lxi]:
                dq.append(i)
                break
            dq.pop()
        if i + 1 < k:
            continue
        sxi = dq[0]
        rs.append(l[sxi])
        if sxi == (i + 1 - k):
            dq.popleft()
    return rs


maxs, mins = slide_max(k, xs), slide_min(k, xs)
aa, bb = xs[:k], xs[k:]
b, nb, bx = aa[0], aa[1], aa[-1]
ba = None
c = 1
for a in aa:
    if ba == None:
        ba = a
        continue
    if a > ba:
        c += 1
    else:
        c = 1
    ba = a
rok = False
if c == k:
    rok = True
r = 1
bs = xs[0]
for i, (s, x) in enumerate(zip(xs[1:], bb)):
    if x > bx:
        c = min(c + 1, k)
    else:
        c = 1
    bx = x
    if c == k:
        if not rok:
            r += 1
        rok = True
        continue
    if x != maxs[i + 1]:
        r += 1
    elif bs != mins[i]:
        r += 1
    bs = s
print(r)

n, k = list(map(int, input().split()))
xs = list(map(int, input().split()))
from collections import deque


def slide_max(k, l):
    rs, rrs = [], set()
    dq = deque()
    for i, x in enumerate(l):
        while True:
            if not len(dq):
                dq.append(i)
                break
            lxi = dq[-1]
            if x < l[lxi]:
                dq.append(i)
                break
            dq.pop()
        if i + 1 < k:
            continue
        sxi = dq[0]
        rs.append(l[sxi])
        if sxi == (i + 1 - k):
            dq.popleft()
    return rs


def slide_min(k, l):
    rs = []
    rrs = set()
    dq = deque()
    for i, x in enumerate(l):
        while True:
            if not len(dq):
                dq.append(i)
                break
            lxi = dq[-1]
            if x > l[lxi]:
                dq.append(i)
                break
            dq.pop()
        if i + 1 < k:
            continue
        if len(dq) == k:
            rrs.add(i + 1 - k)
        sxi = dq[0]
        rs.append(l[sxi])
        if sxi == (i + 1 - k):
            dq.popleft()
    return rs, rrs


maxs, (mins, ns) = slide_max(k, xs), slide_min(k, xs)
r = 1
for i, (s, x) in enumerate(zip(xs, xs[k:])):
    if (x != maxs[i + 1] or s != mins[i]) and (i + 1 not in ns):
        r += 1
if (0 not in ns) and (len(ns) > 0):
    r += 1
print(r)

-    rs = [] +    rs, rrs = [], set() +    rrs = set() +        if len(dq) == k: +            rrs.add(i + 1 - k) -    return rs +    return rs, rrs -maxs, mins = slide_max(k, xs), slide_min(k, xs) -aa, bb = xs[:k], xs[k:] -b, nb, bx = aa[0], aa[1], aa[-1] -ba = None -c = 1 -for a in aa: -    if ba == None: -        ba = a -        continue -    if a > ba: -        c += 1 -    else: -        c = 1 -    ba = a -rok = False -if c == k: -    rok = True +maxs, (mins, ns) = slide_max(k, xs), slide_min(k, xs) -bs = xs[0] -for i, (s, x) in enumerate(zip(xs[1:], bb)): -    if x > bx: -        c = min(c + 1, k) -    else: -        c = 1 -    bx = x -    if c == k: -        if not rok: -            r += 1 -        rok = True -        continue -    if x != maxs[i + 1]: +for i, (s, x) in enumerate(zip(xs, xs[k:])): +    if (x != maxs[i + 1] or s != mins[i]) and (i + 1 not in ns): -    elif bs != mins[i]: -        r += 1 -    bs = s +if (0 not in ns) and (len(ns) > 0): +    r += 1