from collections import deque N=int(input()) A=list(map(int,input().split())) S=set([i for i in range(1,N-1) if A[i-1]A[i+1]]) X=0 while S: i=S.pop() X+=1 A[i]=min(A[i-1],A[i+1])-1 if (i>=2) and A[i-2]A[i]: S.add(i-1) if i<=N-3 and A[i]A[i+2]: S.add(i+1) print(X)