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())
  listH = list(map(int, input().split()))
  minH = min(listH)
  indexF = 0
  while indexF < len(listH):
      listH[indexF] -= minH
      indexF += 1
  sum = minH
  
  
  def getZeroIndex(listH):
      listZeroIndex = []
      index = 0
      while index < len(listH):
          if listH[index] == 0:
              listZeroIndex.append(index)
          index += 1
      return listZeroIndex
  
  
  def mizuyari(listH, listZeroIndex, sum):
      if not 0 in listZeroIndex:
          index = 0
          nextMin = 100
          while index < listZeroIndex[0]:
              if nextMin > listH[index] and listH[index] != 0:
                  nextMin = listH[index]
              index += 1
          index = 0
          sum += nextMin
          while index < listZeroIndex[0]:
              listH[index] -= nextMin
              index += 1
  
      index2 = 0
      while index2 < len(listZeroIndex) - 1:
          nextMin = 100
          index3 = listZeroIndex[index2] + 1
          if index3 == listZeroIndex[index2 + 1]:
              pass
          else:
              while index3 < listZeroIndex[index2 + 1]:
                  if nextMin > listH[index3] and listH[index3] != 0:
                      nextMin = listH[index3]
                  index3 += 1
              index3 = listZeroIndex[index2] + 1
              sum += nextMin
              while index3 < listZeroIndex[index2 + 1]:
                  listH[index3] -= nextMin
                  index3 += 1
          index2 += 1
  
      if listZeroIndex[len(listZeroIndex) - 1] != len(listH) - 1:
          index4 = listZeroIndex[len(listZeroIndex) - 1] + 1
          nextMin = 100
          while index4 < len(listH):
              if listH[index4] < nextMin:
                  nextMin = listH[index4]
              index4 += 1
          index4 = listZeroIndex[len(listZeroIndex) - 1] + 1
          sum += nextMin
          while index4 < len(listH):
              listH[index4] -= nextMin
              index4 += 1
      return listH, sum
  
  
  index5 = 0
  while index5 < 10:
      listZeroIndex = getZeroIndex(listH)
      listH, sum = mizuyari(listH, listZeroIndex, sum)
      if len(listH) == len(listZeroIndex):
          break
      index5 += 1
  print(sum)
  
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"}]