import sys from collections import deque def main(): n = int(sys.stdin.readline()) a = list(map(int, sys.stdin.readline().split())) if n < 3: print(0) return q = deque() for i in range(n-2): if a[i] < a[i+1] and a[i+1] > a[i+2]: q.append(i) count = 0 while q: i = q.popleft() if i < 0 or i >= n-2: continue if a[i] < a[i+1] and a[i+1] > a[i+2]: count += 1 new_val = min(a[i], a[i+2]) - 1 a[i+1] = new_val for next_i in [i-1, i+1]: if 0 <= next_i <= n-3: q.append(next_i) print(count) if __name__ == "__main__": main()