n = int(input()) a = list(map(int, input().split())) dp = [{} for x in range(n)] def solve(i, w, get): if i >= n: return w if dp[i].get(w): return dp[i][w] dp[i][w] = w if get: return solve(i + 1, w, False) return max(solve(i + 1, w, False), solve(i + 1, w + a[i], True)) print(solve(0, 0, False))