n = gets.to_i; h = gets.split.map &:to_i
line = false; count = 0
h.max.times do |i|
	n.times do |j|
		if line == false && h[j] >= i+1
			line = true
			count+=1
		end
		if line == true && h[j] < i+1
			line = false
		end
	end
	line = false
end
puts count
