output_description: Print the number of permutations that can be produced as P after the
  operation.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N K
      P_0 P_1 \cdots P_{N-1}
attempt: class MinSlideWindow:
      def __init__(self, p):
          self.pos_list = []
          self.val_list = p
  
      def put(self, pos):
          val = self.val_list[pos]
  
          while len(self.pos_list) > 0:
              pos1 = self.pos_list[-1]
              val1 = self.val_list[pos1]
              if val1 >= val:
                  del self.pos_list[-1]
              else:
                  break
          self.pos_list.append(pos)
  
      def get(self, pos):
          while len(self.pos_list) > 0:
              pos1 = self.pos_list[0]
              if pos1 <= pos:
                  del self.pos_list[0]
              else:
                  break
  
      def min(self):
          pos1 = self.pos_list[0]
          val1 = self.val_list[pos1]
          return val1
  
  
  class MaxSlideWindow:
      def __init__(self, p):
          self.pos_list = []
          self.val_list = p
  
      def put(self, pos):
          val = self.val_list[pos]
  
          while len(self.pos_list) > 0:
              pos1 = self.pos_list[-1]
              val1 = self.val_list[pos1]
              if val1 <= val:
                  del self.pos_list[-1]
              else:
                  break
          self.pos_list.append(pos)
  
      def get(self, pos):
          while len(self.pos_list) > 0:
              pos1 = self.pos_list[0]
              if pos1 <= pos:
                  del self.pos_list[0]
              else:
                  break
  
      def max(self):
          pos1 = self.pos_list[0]
          val1 = self.val_list[pos1]
          return val1
  
  
  s = input().split(" ")
  n = int(s[0])
  k = int(s[1])
  sp = input().split(" ")
  p = [int(pstr) for pstr in sp]
  num = 0
  ident = False
  before_sort = False
  minw = MinSlideWindow
  maxw = MaxSlideWindow
  
  before_sort_i = 0
  
  for i in range(k - 2):
      minw.put(i)
      maxw.put(i)
  
  for i in range(n - k + 1):
  
      maxw.put(i + k - 2)
      maxw.get(i - 1)
      minw.put(i + k - 2)
      minw.get(i - 1)
  
      if before_sort:
          if p[i + k - 1] < p[i + k - 2]:
              num += 1
              before_sort = False
          else:
              before_sort_i += 1
          continue
  
      else:
          if before_sort_i + k <= i or i <= k:
              for j in range(k - 1):
                  if p[i + j] > p[i + j + 1]:
                      break
              else:
                  if not ident:
                      ident = True
                      num += 1
                  before_sort = True
                  before_sort_i = i
                  continue
  
              if i == 0:
                  num += 1
                  continue
  
              if p[i - 1] > minw.min() or p[i + k - 1] < maxw.max():
                  num += 1
  
          else:
              if p[i - 1] > minw.min() or p[i + k - 1] < maxw.max():
                  num += 1
              if p[i + k - 1] < p[i + k - 2]:
                  before_sort_i = i - 1
  
  
  print(num)
  
problem_description: Statement
  
  Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1).
  
  Now, he will perform the following operation **exactly once** :
  
    * Choose K consecutive elements in P and sort them in ascending order.
  
  Find the number of permutations that can be produced as P after the operation.
samples: [{"input": "5 3\n    0 2 1 4 3", "output": "2\n    \n\nTwo permutations can be produced as P after the operation: (0,1,2,4,3) and\n(0,2,1,3,4).\n\n* * *"}, {"input": "4 4\n    0 1 2 3", "output": "1\n    \n\n* * *"}, {"input": "10 4\n    2 0 1 3 7 5 4 6 8 9", "output": "6"}]