N = int(input()) B = list(map(int, input().split())) M, P = [0] * (N - 1), [0] * (N - 1) for i in range(N - 1): if B[i] < B[i + 1]: P[i] = 1 elif B[i] > B[i + 1]: M[i] = 1 Mc, Pc = [0] * N, [0] * N for i in range(N - 1): Mc[i + 1] = Mc[i] + M[i] Pc[i + 1] = Pc[i] + P[i] ans = 0 for i in range(N): v1 = min(Mc[i], Pc[N - 1] - Pc[i]) v2 = min(Pc[i], Mc[N - 1] - Mc[i]) ans = max(ans, v1, v2) print(ans)