import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,*A = map(int,read().split()) answer = 0 for x,y,z in zip(A,A[1:],A[2:]): answer += ((x < y > z) or (x > y < z)) and (x != z) print(answer)