def read_data(): N = int(input()) As = list(map(int, input().split())) return N, As def solve(N, As): dpL = [1] * N maxR = 1 for i, ai in enumerate(As[1:], 1): maxR = update_dp(dpL, maxR, i, ai, As) return max(max(dpL), maxR) def update_dp(dpL, maxR, i, ai, As): dptmp = [1] * i maxtmp = 1 for j in range(i-1, -1, -1): aj = As[j] if aj > ai and dpL[j] >= maxtmp: maxtmp = dpL[j] + 1 dptmp[j] = maxtmp if maxR < maxtmp: maxR = maxtmp for j, aj in enumerate(As[:i]): if aj < ai and dptmp[j] >= dpL[j]: dpL[j] = dptmp[j] + 1 return maxR N, As = read_data() print(solve(N, As))