from collections import deque n = int(input()) a = list(map(int, input().split())) queue = deque() # Find initial peaks (0-based index) for i in range(1, n-1): if a[i-1] < a[i] and a[i] > a[i+1]: queue.append(i) count = 0 while queue: i = queue.popleft() # Check if i is still a valid peak if i < 1 or i >= n-1: continue left = a[i-1] current = a[i] right = a[i+1] if left < current and current > right: # Perform the operation new_val = min(left, right) - 1 a[i] = new_val count += 1 # Check neighboring positions for new peaks for j in [i-1, i+1]: if 0 < j < n-1: # Check if j is a peak if a[j-1] < a[j] and a[j] > a[j+1]: queue.append(j) print(count)