#include using namespace std; typedef pair P; typedef long long ll; typedef long double ld; const int inf=1e9+7; const ll longinf=1LL<<60; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) #define F first #define S second constexpr char ln = '\n'; const int mx=200010; const ll mod=1e9+7; int main(){ int n; cin >> n; vector c(n); set str,stl; rep(i,n){ cin >> c[i]; str.insert(c[i]); } int ans = inf; stl.insert(c[0]); str.erase(c[0]); REP(i,1,n-1){ str.erase(c[i]); auto posl = stl.lower_bound(c[i]); auto posr = str.lower_bound(c[i]); if(posl!=stl.begin() && posr!=str.begin()){ ans = min(ans, c[i]+*stl.begin()+*str.begin()); } if(posl!=stl.end() && posr!=str.end()){ ans = min(ans, c[i]+*posl+*posr); } stl.insert(c[i]); } if(ans==inf) ans = -1; cout << ans << ln; return 0; }