N=int(input()) A=list(map(int, input().split())) LMI=[0 for i in range(N)] RMI=[0 for i in range(N)] mi,ma=10**9,0 for i in range(N): mi=min(A[i],mi) LMI[i]=mi mi,ma=10**9,0 for i in range(N): mi=min(A[-1-i],mi) RMI[-1-i]=mi ans=10**9 for i in range(1,N-1): if LMI[i-1]RMI[i+1]: d=LMI[i-1]+A[i]+RMI[i+1] ans=min(d,ans) for i in range(1,N-1): if LMI[i-1]>A[i] and A[i]