N=int(input()) A=[int(x) for x in input().split()] import heapq q=[] for i in range(N): heapq.heappush(q,(-A[i],i)) ans=0 while q: c,x=heapq.heappop(q) if x==0 or x==N-1: continue if A[x-1]A[x+1]: A[x]=min(A[x-1],A[x+1])-1 heapq.heappush(q,(-A[x],x)) ans+=1 print(ans)