# -*- coding: utf-8 -*- N = input() cnt = 0 ref = [] Alist = map(int, raw_input().split()) for i in range(0, len(Alist)-2): j = (Alist[i+2] - Alist[i+1]) * (Alist[i+1] - Alist[i]) if j < 0 and Alist[i+2] != Alist[i]: cnt += 1 print cnt