#include using namespace std; int main(){ const int MOD = 1e9 + 7; int n; cin >> n; bool big = false; long long rem = 1; for(int i = 0; i < n; i++){ int a; cin >> a; if(a == 0){ cout << -1 << endl; return 0; }else if(a >= 4){ big = true; }else{ int f = 1; for(int j = 1; j <= a; j++){ f *= j; } for(int j = 0; j < f; j++){ rem *= a; } if(rem > MOD){ big = true; } } } if(big) cout << MOD << endl; else cout << MOD % rem << endl; return 0; }