N = int(input()) V = list(map(int,input().split())) V.extend([0,0,0]) value = 0 key = 0 for i in len(V)-2: if key == 2: key = 1 continue elif key == 1: key = 0 continue else: if V[i+1]+V[i+3] > V[i]+V[i+2] and V[i+1]+V[i+3] > V[i]+V[i+3]: value += V[i+1] key = 2 else: value += V[i] key = 1 print(value)