n = int(input()) a = list(map(int,input().split())) res = 0 for i in range(n-2): l = a[i:i+3] mid = sorted(l)[1] if max(l)!=mid and min(l)!=mid and l[1]!=mid: res += 1 print(res)