N = gets.to_i
heights = gets.split(" ").map(&:to_i)
ary = []
(1..heights.max).each do |num|
  row_ary = []
  heights.each do |height|
    if height >= num
      row_ary << 1
    else
      row_ary << 0
    end
  end
  ary << row_ary
end

#ary [[1,1,1,1], [0,1,1,0]]みたいな形
needs_num = 0
ary.each do |row_ary|
  row_ary.each_with_index do |current_val, idx|
    if current_val == 1 && row_ary[idx+1] == 0
      needs_num += 1
    end
    if current_val == 1 && row_ary[idx+1].nil?
      needs_num += 1
    end
  end
end

puts needs_num