N = int(input())a = list(map(int,input().split()))cm=0
for i in range(1,N-1): if a[i] ==0: if a[i-1]>a[i+1]: cm +=(a[i+1]) else: cm +=(a[i-1])
if a[0]==0: cm +=(a[0+1])if a[-1]==0: cm +=(a[-1-1])print(cm)