N = input() A = map(int, raw_input().split()) res = 0 for i in range(N - 2): a = A[i] b = A[i + 1] c = A[i + 2] list1 = [[a, 1], [b, 2], [c, 3]] sortlist1= sorted(list1, key=lambda x:x[0], reverse=True) if (a == b or b == c or a == c): continue if (sortlist1[1][1] != 2): res += 1 print res