import collections tmp = input() N = [int(i) for i in input().strip().split(' ')] c = 0 for i in range(len(N) - 2): d = sorted(N[i:i+3])[1] if N[i+1] != d: if len(collections.Counter(N[i:i+3])) == 3: c += 1 print('{}'.format(c))