import sys

sys.setrecursionlimit(10 ** 9)

input = sys.stdin.readline

from itertools import permutations,  combinations, accumulate

from functools import *

from collections import deque, defaultdict, Counter

from heapq import heapify, heappop, heappush, heappushpop



INF = float('inf')

NIL = - 1



""" Input

S = input().rstrip()



N, A, B = map(int, input().split())



A = np.array(input().split(), dtype=np.float64)

D = [int(input()) for _ in range(N)]

AB = [[int(x) for x in input().split()] for _ in range(N)]

PX = [[int(x) for x in input().split()] for _ in range(Q)]

"""

N = int(eval(input()))

P = list(map(int, input().split()))

counter = 0

for i in range(1, len(P) - 1):

    if (P[i - 1] < P[i] and P[i] < P[i + 1]) or (P[i - 1] > P[i] and P[i] > P[i + 1]):

        counter += 1



print(counter)







# def main():



# if __name__ == '__main__':

#     main()

import sys

sys.setrecursionlimit(10 ** 9)

input = sys.stdin.readline

from itertools import permutations,  combinations, accumulate

from functools import *

from collections import deque, defaultdict, Counter

from heapq import heapify, heappop, heappush, heappushpop



INF = float('inf')

NIL = - 1





N = int(eval(input()))

P = list(map(int, input().split()))

counter = 0

for i in range(1, len(P) - 1):

    if (P[i - 1] < P[i] < P[i + 1]) or (P[i - 1] > P[i] > P[i + 1]):

        counter += 1



print(counter)

import sys

sys.setrecursionlimit(10**9)
input = sys.stdin.readline
from itertools import permutations, combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float("inf")
NIL = -1
""" Input
S = input().rstrip()
N, A, B = map(int, input().split())
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""
N = int(eval(input()))
P = list(map(int, input().split()))
counter = 0
for i in range(1, len(P) - 1):
    if (P[i - 1] < P[i] and P[i] < P[i + 1]) or (P[i - 1] > P[i] and P[i] > P[i + 1]):
        counter += 1
print(counter)
# def main():
# if __name__ == '__main__':
#     main()

import sys

sys.setrecursionlimit(10**9)
input = sys.stdin.readline
from itertools import permutations, combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float("inf")
NIL = -1
N = int(eval(input()))
P = list(map(int, input().split()))
counter = 0
for i in range(1, len(P) - 1):
    if (P[i - 1] < P[i] < P[i + 1]) or (P[i - 1] > P[i] > P[i + 1]):
        counter += 1
print(counter)

-""" Input -S = input().rstrip() -N, A, B = map(int, input().split()) -A = np.array(input().split(), dtype=np.float64) -D = [int(input()) for _ in range(N)] -AB = [[int(x) for x in input().split()] for _ in range(N)] -PX = [[int(x) for x in input().split()] for _ in range(Q)] -""" -    if (P[i - 1] < P[i] and P[i] < P[i + 1]) or (P[i - 1] > P[i] and P[i] > P[i + 1]): +    if (P[i - 1] < P[i] < P[i + 1]) or (P[i - 1] > P[i] > P[i + 1]): -# def main(): -# if __name__ == '__main__': -#     main()