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

count =0
loop do
    break if h.all?{|x|x==0}
    l=h.index{|x|x!=0}
    (l...h.size).each{|i|
        break if h[i]==0;
        h[i]-=1
    }
    count +=1
end


print count