n,d,a=int(input()),list(map(int,input().split())),0 for i in range(n-2): b=d[i:i+3] a+=(len({*b})>2)*(b[1]!=sorted(b)[1]) print(a)