def max_operations(): import sys input = sys.stdin.read().split() n = int(input[0]) a = list(map(int, input[1:n+1])) ops = 0 i = 0 while i <= n-3: if a[i] < a[i+1] and a[i+1] > a[i+2]: min_val = min(a[i], a[i+2]) a[i+1] = min_val - 1 ops += 1 i = max(i-1, 0) # 检查前面的位置是否满足条件 else: i += 1 print(ops) max_operations()