n = gets.chomp!.to_i
hs = gets.chomp!.split(" ").map{|item| item.to_i}
ans = 0
while !hs.all?(0)
n.downto(1){|i|
	flag = false
	for j in 1..n-i
		if hs[j-1..j+i-1].include?(0) == false then
			for k in j-1..j+i-1
			hs[k]=hs[k]-1
			end
			flag=true 
			ans += 1
			break
		end
	end
	if flag then break end
}
end

puts ans