#include int main(){ using namespace std; constexpr unsigned long MOD{1000000007}; unsigned long N; cin >> N; vector A(N); for(auto&& i : A)cin >> i; if(any_of(begin(A), end(A), [](const auto& i){return i == 0;}))return 0 & puts("-1"); if(any_of(begin(A), end(A), [](const auto& i){return i >= 4;}))return 0 & puts("1000000007"); unsigned long ans{1}; for(const auto& i : A){ for(unsigned long j{[](const auto& x){unsigned long ret{1}; for(unsigned long i{1}; i <= x; ++i)ret *= i;return ret;}(i)}; j--; )ans *= i; if(ans > MOD)return 0 & puts("1000000007"); } cout << MOD % ans << endl; return 0; }