def dif(a,b,c): return (a!=b and b!=c and c!=a) def main(): n=int(input()) l_list=list(map(int,input().split())) cnt=0 for i in range(len(l_list)-2): a=l_list[i] b=l_list[i+1] c=l_list[i+2] cnt=cnt+1 if dif(a,b,c) and (b==max(a,b,c) or b==min(a,b,c)) else cnt print(cnt) if __name__ == "__main__": main()