n = gets.to_i
h = gets.split.map(&:to_i)

max = h.max
arr = Array.new(n) { Array.new(max) { 0 } }
h.each_with_index { |e, idx| arr[idx].fill(1, 0...e) }

puts arr.transpose.map { |e| e.join.squeeze.count('1') }.inject(0, :+)