n=int(input()) a=[10**12]+list(map(int,input().split()))+[10**12] s=[] def ok(i): return a[i-1]a[i+1] for i in range(1,n+1): if ok(i):s.append(i) ans=0 while s: i=s.pop() ans+=1 a[i]=min(a[i-1],a[i+1])-1 if ok(i-1):s.append(i-1) if ok(i+1):s.append(i+1) print(ans)