N = gets.to_i
h_array = gets.split.map(&:to_i)
count = 0

N.downto(1){|diff_num|
  start_array = [*1..((h_array.length)-(diff_num-1))]

  start_array.each do |start|
    last_flag = false

    loop do
      (start..(start+(diff_num-1))).each do |seq|
        if h_array[seq-1] == 0
          last_flag = true
          break
        end
      end

      unless last_flag
        (start..(start+(diff_num-1))).each do |seq|
          h_array[seq-1] -= 1
        end

        count += 1
      end

      break if last_flag
    end
  end
}

puts count
