n=gets.to_i
h=gets.split.map(&:to_i)
ans=0
100.downto(1){|height|
  idx=[]
  connected=false
  h.each_with_index{|flower_height,i|
    if flower_height==height
      unless connected
        connected=true
        ans+=1
      end
      idx << i
    else
      connected=false
    end
  }
  idx.each{|i|h[i]-=1}
}

puts ans