from subprocess import*

call(('pypy3','-c',"""

def main():

  def update(k,x):

    k+=N0-1

    data_min[k]=data_max[k]=x

    while k>=0:

      k=(k-1)//2

      a,b=data_min[2*k+1],data_min[2*k+2]

      data_min[k]=a if a<b else b

      a,b=data_max[2*k+1],data_max[2*k+2]

      data_max[k]=a if a>b else b

  def query_min(l,r):

    L,R=l+N0,r+N0

    s=INF

    while L<R:

      if R&1:

        R-=1

        t=data_min[R-1]

        if t<s:s=t

      if L&1:

        t=data_min[L-1]

        if t<s:s=t

        L+=1

      L//=2

      R//=2

    return s

  def query_max(l,r):

    L,R=l+N0,r+N0

    s=0

    while L<R:

      if R&1:

        R-=1

        t=data_max[R-1]

        if t>s:s=t

      if L&1:

        t=data_max[L-1]

        if t>s:s=t

        L+=1

      L//=2

      R//=2

    return s

  n,k,*p=map(int,open(0).read().split())

  N0=2**(n-1).bit_length()

  INF=10**18

  data_min=[INF]*2*N0

  data_max=[0]*2*N0

  c=[0]

  for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),

  *c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]

  x=not f

  for i,q in enumerate(p):update(i,q)

  for i,(a,b,c)in enumerate(zip(p,p[k:],c)):

    f|=c

    if not c and(a!=query_min(i,i+k)or b!=query_max(i+1,i+k+1)):x+=1

  print(x+f)

main()

"""))
class SWAG():

    def __init__(self,unit,f):

        self.fold_r=[unit]

        self.fold_l=[unit]

        self.data_r=[]

        self.data_l=[]

        self.f=f

    def __refill_right(self):

        temp=[]

        n=len(self.data_l)

        for _ in range(n//2):

            temp.append(self.popleft())

        for _ in range(n//2,n):

            self.append(self.popleft())

        for t in temp[::-1]:

            self.appendleft(t)

    def __refill_left(self):

        temp=[]

        n=len(self.data_r)

        for _ in range(n//2):

            temp.append(self.pop())

        for _ in range(n//2,n):

            self.appendleft(self.pop())

        for t in temp[::-1]:

            self.append(t)

    def append(self,x):

        self.fold_r.append(self.f(self.fold_r[-1],x))

        self.data_r.append(x)

    def appendleft(self,x):

        self.fold_l.append(self.f(self.fold_l[-1],x))

        self.data_l.append(x)

    def pop(self):

        if not self.data_r:

            self.__refill_right()

        self.fold_r.pop()

        return self.data_r.pop()

    def popleft(self):

        if not self.data_l:

            self.__refill_left()

        self.fold_l.pop()

        return self.data_l.pop()

    def fold_all(self):

        return self.f(self.fold_r[-1],self.fold_l[-1])

n,k,*p=list(map(int,open(0).read().split()))

c=[0]

for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),

*c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]

x=not f

s_min=SWAG(10**18,min)

s_max=SWAG(0,max)

*_,=list(map(s_min.append,p[:k-1]))

*_,=list(map(s_max.append,p[1:k]))

for i,(a,b,c)in enumerate(zip(p,p[k:],c)):

    f|=c

    s_min.append(p[i+k-1])

    s_max.append(b)

    if not c and(a!=s_min.fold_all()or b!=s_max.fold_all()):x+=1

    s_min.popleft()

    s_max.popleft()

print((x+f))
from subprocess import *

call(
    (
        "pypy3",
        "-c",
        """
def main():
  def update(k,x):
    k+=N0-1
    data_min[k]=data_max[k]=x
    while k>=0:
      k=(k-1)//2
      a,b=data_min[2*k+1],data_min[2*k+2]
      data_min[k]=a if a<b else b
      a,b=data_max[2*k+1],data_max[2*k+2]
      data_max[k]=a if a>b else b
  def query_min(l,r):
    L,R=l+N0,r+N0
    s=INF
    while L<R:
      if R&1:
        R-=1
        t=data_min[R-1]
        if t<s:s=t
      if L&1:
        t=data_min[L-1]
        if t<s:s=t
        L+=1
      L//=2
      R//=2
    return s
  def query_max(l,r):
    L,R=l+N0,r+N0
    s=0
    while L<R:
      if R&1:
        R-=1
        t=data_max[R-1]
        if t>s:s=t
      if L&1:
        t=data_max[L-1]
        if t>s:s=t
        L+=1
      L//=2
      R//=2
    return s
  n,k,*p=map(int,open(0).read().split())
  N0=2**(n-1).bit_length()
  INF=10**18
  data_min=[INF]*2*N0
  data_max=[0]*2*N0
  c=[0]
  for a,b in zip(p,p[1:]):c+=c[-1]+(a<b),
  *c,f=[b-a==k-1for a,b in zip(c,c[k-1:])]
  x=not f
  for i,q in enumerate(p):update(i,q)
  for i,(a,b,c)in enumerate(zip(p,p[k:],c)):
    f|=c
    if not c and(a!=query_min(i,i+k)or b!=query_max(i+1,i+k+1)):x+=1
  print(x+f)
main()
""",
    )
)

class SWAG:
    def __init__(self, unit, f):
        self.fold_r = [unit]
        self.fold_l = [unit]
        self.data_r = []
        self.data_l = []
        self.f = f

    def __refill_right(self):
        temp = []
        n = len(self.data_l)
        for _ in range(n // 2):
            temp.append(self.popleft())
        for _ in range(n // 2, n):
            self.append(self.popleft())
        for t in temp[::-1]:
            self.appendleft(t)

    def __refill_left(self):
        temp = []
        n = len(self.data_r)
        for _ in range(n // 2):
            temp.append(self.pop())
        for _ in range(n // 2, n):
            self.appendleft(self.pop())
        for t in temp[::-1]:
            self.append(t)

    def append(self, x):
        self.fold_r.append(self.f(self.fold_r[-1], x))
        self.data_r.append(x)

    def appendleft(self, x):
        self.fold_l.append(self.f(self.fold_l[-1], x))
        self.data_l.append(x)

    def pop(self):
        if not self.data_r:
            self.__refill_right()
        self.fold_r.pop()
        return self.data_r.pop()

    def popleft(self):
        if not self.data_l:
            self.__refill_left()
        self.fold_l.pop()
        return self.data_l.pop()

    def fold_all(self):
        return self.f(self.fold_r[-1], self.fold_l[-1])


n, k, *p = list(map(int, open(0).read().split()))
c = [0]
for a, b in zip(p, p[1:]):
    c += (c[-1] + (a < b),)
*c, f = [b - a == k - 1 for a, b in zip(c, c[k - 1 :])]
x = not f
s_min = SWAG(10**18, min)
s_max = SWAG(0, max)
(*_,) = list(map(s_min.append, p[: k - 1]))
(*_,) = list(map(s_max.append, p[1:k]))
for i, (a, b, c) in enumerate(zip(p, p[k:], c)):
    f |= c
    s_min.append(p[i + k - 1])
    s_max.append(b)
    if not c and (a != s_min.fold_all() or b != s_max.fold_all()):
        x += 1
    s_min.popleft()
    s_max.popleft()
print((x + f))

-from subprocess import * +class SWAG: +    def __init__(self, unit, f): +        self.fold_r = [unit] +        self.fold_l = [unit] +        self.data_r = [] +        self.data_l = [] +        self.f = f -call( -    ( -        "pypy3", -        "-c", -        """ -def main(): -  def update(k,x): -    k+=N0-1 -    data_min[k]=data_max[k]=x -    while k>=0: -      k=(k-1)//2 -      a,b=data_min[2*k+1],data_min[2*k+2] -      data_min[k]=a if a<b else b -      a,b=data_max[2*k+1],data_max[2*k+2] -      data_max[k]=a if a>b else b -  def query_min(l,r): -    L,R=l+N0,r+N0 -    s=INF -    while L<R: -      if R&1: -        R-=1 -        t=data_min[R-1] -        if t<s:s=t -      if L&1: -        t=data_min[L-1] -        if t<s:s=t -        L+=1 -      L//=2 -      R//=2 -    return s -  def query_max(l,r): -    L,R=l+N0,r+N0 -    s=0 -    while L<R: -      if R&1: -        R-=1 -        t=data_max[R-1] -        if t>s:s=t -      if L&1: -        t=data_max[L-1] -        if t>s:s=t -        L+=1 -      L//=2 -      R//=2 -    return s -  n,k,*p=map(int,open(0).read().split()) -  N0=2**(n-1).bit_length() -  INF=10**18 -  data_min=[INF]*2*N0 -  data_max=[0]*2*N0 -  c=[0] -  for a,b in zip(p,p[1:]):c+=c[-1]+(a<b), -  *c,f=[b-a==k-1for a,b in zip(c,c[k-1:])] -  x=not f -  for i,q in enumerate(p):update(i,q) -  for i,(a,b,c)in enumerate(zip(p,p[k:],c)): -    f|=c -    if not c and(a!=query_min(i,i+k)or b!=query_max(i+1,i+k+1)):x+=1 -  print(x+f) -main() -""", -    ) -) +    def __refill_right(self): +        temp = [] +        n = len(self.data_l) +        for _ in range(n // 2): +            temp.append(self.popleft()) +        for _ in range(n // 2, n): +            self.append(self.popleft()) +        for t in temp[::-1]: +            self.appendleft(t) + +    def __refill_left(self): +        temp = [] +        n = len(self.data_r) +        for _ in range(n // 2): +            temp.append(self.pop()) +        for _ in range(n // 2, n): +            self.appendleft(self.pop()) +        for t in temp[::-1]: +            self.append(t) + +    def append(self, x): +        self.fold_r.append(self.f(self.fold_r[-1], x)) +        self.data_r.append(x) + +    def appendleft(self, x): +        self.fold_l.append(self.f(self.fold_l[-1], x)) +        self.data_l.append(x) + +    def pop(self): +        if not self.data_r: +            self.__refill_right() +        self.fold_r.pop() +        return self.data_r.pop() + +    def popleft(self): +        if not self.data_l: +            self.__refill_left() +        self.fold_l.pop() +        return self.data_l.pop() + +    def fold_all(self): +        return self.f(self.fold_r[-1], self.fold_l[-1]) + + +n, k, *p = list(map(int, open(0).read().split())) +c = [0] +for a, b in zip(p, p[1:]): +    c += (c[-1] + (a < b),) +*c, f = [b - a == k - 1 for a, b in zip(c, c[k - 1 :])] +x = not f +s_min = SWAG(10**18, min) +s_max = SWAG(0, max) +(*_,) = list(map(s_min.append, p[: k - 1])) +(*_,) = list(map(s_max.append, p[1:k])) +for i, (a, b, c) in enumerate(zip(p, p[k:], c)): +    f |= c +    s_min.append(p[i + k - 1]) +    s_max.append(b) +    if not c and (a != s_min.fold_all() or b != s_max.fold_all()): +        x += 1 +    s_min.popleft() +    s_max.popleft() +print((x + f))