N = int(raw_input()) A = map(int, raw_input().split()) cnt = 0 for i in range(1, N-1): now = [A[i-1], A[i], A[i+1]] now.sort() if now[1] != A[i] and now[0] != now[1] and now[1] != now[2] and now[2] != now[0]: cnt += 1 print cnt