n = int(input()) seq = input().split() count = 0 for i in range(n - 2): if seq[i] == seq[i+2]: break elif seq[i] > seq[i+1] and seq[i+1] < seq[i+2]: count += 1 elif seq[i] < seq[i+1] and seq[i+1] > seq[i+2]: count += 1 print(count)