MOD=10**9+7
cnt=0; sum=0; prev=nil; ha=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n = gi
h = gsmi

cnt = 0
while h.sort[-1] > 0 do
  prev = -1
  0.upto(n-1) do |i|
    cnt+=1 if h[i]>0 && prev<0
    h[i]-=1
    prev=h[i]
  end
end
puts cnt
