n = int(input()) s = list(map(int, input().split())) cnt = 0 for i in range(n-2): a = s[i] b = s[i+1] c = s[i+2] if a < b and b > c and a != c: cnt += 1 elif a > b and b < c and a != c: cnt += 1 print(cnt)