N=input() A=map(int,raw_input().split()) dp=[[[None]*N for _ in range(N)] for _ in [0,1]] for i in range(N): dp[0][i][i]=dp[1][i][i]=1 for d in range(1,N): for l in range(N-d): r=l+d if A[l]>=A[r]: dp[0][l][r]=dp[0][l][r-1] else: dp[0][l][r]=max(dp[0][l][r-1],dp[1][l+1][r]+1) if A[l]<=A[r]: dp[1][l][r]=dp[1][l+1][r] else: dp[1][l][r]=max(dp[1][l+1][r],dp[0][l][r-1]+1) print max([dp[0][i][N-1] for i in range(N)]+dp[1][0])