# frozen_string_literal: true

# ABC 140 C - Maximum value

STDIN.gets

input_a = STDIN.gets.split(' ').map(&:to_i)
result = [input_a.first]

input_a[0..(input_a.length - 1)].each_with_index do |a, idx|
  result << a
  result[idx] = a if result[idx] > a
end

puts result.inject(:+)
