#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 { vll pfac = {0, 1, 4, 729}; ll ans = 1; for (int i = 0; i < n; i++) { if (a[i] >= 4 || ans * pfac[a[i]] > MAX) { ans = MAX + 1; break; } ans *= pfac[a[i]]; } cout << MAX % ans << '\n'; } return 0; }