n = int(input()) V = list(map(int,input().split())) if n == 1 : print(V[0]) elif n == 2: print(max(V)) else: dp = [0] * n dp[0] = V[0] dp[1] = max(V[0], V[1]) for i, v in enumerate(V[2:], 2): dp[i] = max(dp[i-1], dp[i-2] + v) print(dp[n-1])