output_description: Print the minimum number of watering operations required to satisfy the
  condition.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      h_1 h_2 h_3 ...... h_N
attempt: N = int(input())
  hs = [int(val) for val in input().split(" ")]
  # num = len(hs)
  # start_idx = None
  # end_idx = None
  # op_num = 0
  # last_op_idx = None
  # while sum(hs) > 0:
  #     for i in range(num):
  #         if hs[i] > 0:
  #             hs[i] -= 1
  #             last_op_idx = i
  #             if i == num - 1:
  #                 op_num += 1
  #         else:
  #             if i >= 1 and last_op_idx == i-1:
  #                 op_num += 1
  # print(op_num)
  
  
  def recursion(hs, op_num):
      if not hs:
          return op_num - 1
      if min(hs) >= 1:
          return recursion([val - 1 for val in hs], op_num + 1)
  
      results = []
      curr_results = []
      for i in range(len(hs)):
          if hs[i] >= 1:
              curr_results.append(hs[i] - 1)
          else:
              results.append(curr_results)
              curr_results = []
      results.append(curr_results)
      for result in results:
          op_num += recursion(result, 1)
      return op_num
  
  
  print(recursion(hs, 0))
  
problem_description: Statement
  
  In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the
  heights of all flowers are 0. You are given a sequence
  h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of
  Flower k to h_k for all k (1 \leq k \leq N), by repeating the following
  "watering" operation:
  
    * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r.
  
  Find the minimum number of watering operations required to satisfy the
  condition.
samples: [{"input": "4\n    1 2 2 1", "output": "2\n    \n\nThe minimum number of watering operations required is 2. One way to achieve it\nis:\n\n  * Perform the operation with (l,r)=(1,3).\n  * Perform the operation with (l,r)=(2,4).\n\n* * *"}, {"input": "5\n    3 1 2 3 1", "output": "5\n    \n\n* * *"}, {"input": "8\n    4 23 75 0 23 96 50 100", "output": "221"}]