n = int(input()) *a, = map(int,input().split()) def is_kadomatu(x,y,z): return x != z and (x < y > z or x > y < z) print(sum(is_kadomatu(a[i],a[i+1],a[i+2]) for i in range(n-2)))