i = gets.to_i
ps = gets.strip.split.map(&:to_i)

r = 0

while true
    ps = ps.drop_while{|j| j == 0 }
    break unless ps.any?
    j = 0
    while j < ps.length and ps[j] > 0
        ps[j] -= 1
        j += 1
    end

    r += 1
end

puts r