from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N = int(input()) A = list(map(int,input().split())) ans = 0 for i in range(1,N-1): ans += (A[i]>A[i-1])&(A[i]>A[i+1])&(A[i-1]!=A[i+1]) ans += (A[i]