#include using namespace std; #define ll long long #define PI acos(-1) const int mod = 1e9+7; ll bigMod(ll a,ll b) { ll ans=1; while(b) { if(b&1) ans = (ans*a); a = (a*a); b >>=1; } return ans; } int main() { int n; cin >> n; vectorarr(n); for(int i=0; i> arr[i]; } sort(arr.begin(),arr.end()); ll answer = 1; ll mn = arr[0]; ll mx = arr[n-1]; if(mn == 0) answer = -1; else if(mx >=4 )answer = mod; else { ll ans = 1; for(ll x : arr) { if(x==1)ans = (ans * bigMod(x,1)); else if(x==2)ans = (ans * bigMod(x,2)); else if(x==3)ans = (ans * bigMod(x,6)); if(ans>mod || ans<0) { answer = mod; break; } if(mod % ans == 0) { answer = -1; break; } answer = mod % ans; } } cout << answer << endl; }