def main(): N = int(input()) *A, = map(int, input().split()) DP = [[0]*N for i in range(N)] order = sorted(range(N), key=lambda x: A[x], reverse=True) for i in order: DP[i][i] = 1 for j in range(i-1, -1, -1): DP[i][j] = DP[i][j+1] if A[i] < A[j]: DP[i][j] = max(DP[i][j], DP[j][i-1]+1) for j in range(i+1, N): DP[i][j] = DP[i][j-1] if A[i] < A[j]: DP[i][j] = max(DP[i][j], DP[j][i+1]+1) print(max(map(max, DP))) if __name__ == '__main__': main()