#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll=long long; template using V = vector; template using P = pair; using vll = V; using vvll = V; #define ALL(v) v.begin(),v.end() template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; } template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; } #define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<> n; vll a(n); for (int i = 0; i < n; i++) cin >> a[i]; if (*min_element(ALL(a)) == 0) cout << -1 << '\n'; else { ll ans = 1; for (int i = 0; i < n; i++) { for (int j = a[i]; j >= 1; j--) { for (int k = 0; k < j; k++) { ans *= a[i]; if (ans > MAX) goto FINAL; } } } FINAL: cout << MAX % ans << '\n'; } return 0; }