n = int(input()) lt = list(map(int,input().split())) g = [i for i in lt] for i in range(n): for j in range(i): if lt[i] > lt[j]: g[i] = max(g[i], g[j] + lt[i]) print(max(g))