program main
implicit None
	integer(8)::n,i,j,p
	integer(8),allocatable::h(:)
	
	read*,n
	allocate(h(n))
	read*,h
	
	p = 0
	do i = 1,n
		do
			if(h(i) == 0) exit
			do j = i,n
				if(h(j) == 0) exit
				h(j) = h(j)-1
			enddo
			p = p + 1
		enddo
	enddo
	print "(i0)",p
end program main