def count_operations(N, A): def is_peak(i): return 0 < i < N - 1 and A[i - 1] < A[i] > A[i + 1] peaks = [i for i in range(1, N - 1) if is_peak(i)] count = 0 while peaks: i = peaks.pop() count += 1 A[i] = min(A[i - 1], A[i + 1]) - 1 for j in (i - 1, i + 1): if 0 < j < N - 1 and is_peak(j) and j not in peaks: peaks.append(j) return count N = int(input()) A = list(map(int, input().split())) result = count_operations(N, A) print(result)