#include using namespace std; int INF = 1000000000; int main(){ int N; cin >> N; vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } int ans = INF; for (int i = 0; i < N; i++){ for (int j = i + 1; j < N; j++){ for (int k = j + 1; k < N; k++){ if ((A[i] < A[j] && A[j] > A[k]) || (A[i] > A[j] && A[j] < A[k])){ ans = min(ans, A[i] + A[j] + A[k]); } } } } if (ans == INF){ cout << -1 << endl; } else { cout << ans << endl; } }