N = int(input()) V = list(map(int,input().split())) V.extend([0,0,0]) value = 0 key = 0 for i in range(len(V)-3): if 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]: continue else: value += V[i] key = 1 print(value)