#include <bits/stdc++.h>   using namespace std;   int n, a[400 + 2], ans = 1 << 30;   int main() {     cin >> n;     for (register int i = 1; i <= n; i++) cin >> a[i];     for (int i = n; i >= 2; i--) {       if (a[i] >= ans) break;       for (int j = i; j <= n; j++) {         register int num = a[i - 1] - 1, x = 1, t;         for (register int k = i; k <= j; k++)           if (num >= a[k]) {             t = num / a[k];             x += t, num -= t * a[k];           }         num = a[i - 1] - 1 - num + a[j];         int res = num;         if (res < ans) {           for (register int k = 1; k <= n; k++)             if (num >= a[k]) {               t = num / a[k];               x -= t, num -= t * a[k];               if (x < 0) break;             }           if (x < 0) ans = res;         }       }     }     if (ans == 1 << 30) ans = -1;     cout << ans << endl;     return 0;   }   