import sys
from collections import deque

def main():
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    peaks = deque()
    # Find initial peaks (0-based indices)
    for i in range(N - 2):
        if A[i] < A[i + 1] and A[i + 1] > A[i + 2]:
            peaks.append(i + 1)  # Peak at position i+1 (0-based)
    count = 0
    while peaks:
        m = peaks.popleft()
        left = m - 1
        right = m + 1
        # Check if current position is still a valid peak
        if left < 0 or right >= N:
            continue
        if A[left] < A[m] and A[m] > A[right]:
            # Process the peak
            min_val = min(A[left], A[right]) - 1
            A[m] = min_val
            count += 1
            # Check left triplet (m-2, m-1, m)
            if m - 2 >= 0:
                new_mid = m - 1
                if A[m - 2] < A[new_mid] and A[new_mid] > A[m]:
                    peaks.append(new_mid)
            # Check right triplet (m, m+1, m+2)
            if m + 2 < N:
                new_mid = m + 1
                if A[m] < A[new_mid] and A[new_mid] > A[m + 2]:
                    peaks.append(new_mid)
    print(count)

if __name__ == '__main__':
    main()