#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the maxSubsetSum function below.
def maxSubsetSum(arr):
    n=len(arr)
    X=[0]*n
    X[0]=arr[0]
    X[1]=max(arr[1],X[0])
    for i in range(2,n):
        X[i]=max(arr[i],X[i-1],arr[i]+X[i-2])
        
    return X[-1]    

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    n = int(input())

    arr = list(map(int, input().rstrip().split()))

    res = maxSubsetSum(arr)

    fptr.write(str(res) + '\n')

    fptr.close()
