n = int(input()) aa = list(map(int,input().split())) n+=100 aa+=[0]*100 aasum = sum(aa) result = aasum for l in range(n-1): for r in range(l,n): if (r-l)%2: continue bb = [0]*n for x in range(l,r+1): bb[x] = min(x-l,r-x)+1 if sum(bb) > aasum: continue s = 0 for x in range(n): s+= max(0,aa[x]-bb[x]) # 減らす方のみカウント result = min(result,s) print(result)