program ccc
implicit none

integer :: n, i, j, st, en, res
integer,allocatable,dimension(:) :: h

read*, n
allocate(h(0:n+1))
read*, h(1:n)

h(0)=0
h(n+1)=0
st=0
en=0
res=0

do while(sum(h)/=0)

do i=0,n
if(h(i)==0.and.h(i+1)/=0) then
st=i+1
exit
end if
end do
do i=0,n
if(h(i)/=0.and.h(i+1)==0) then
en=i
exit
end if
end do

do i=st,en
h(i)=h(i)-1
end do

res=res+1

end do

write(*,'(i0)') res

end program