#include using namespace std; long long PreGarner(vector &B,vector &M,long long MOD){ long long ret = 1; for(int i=0; i &B,vector &M,long long MOD){ M.push_back(MOD); vector mulM(M.size(),1),value(M.size(),0); for(int i=0; i> N; vector B,M; bool allzero = true; while(N--){ int b,m; cin >> b >> m; if(b) allzero = false; B.push_back(b); M.push_back(m); } long long mod = 1e9+7; long long lcm = PreGarner(B,M,mod); if(lcm == -1 || allzero) cout << lcm << endl; else cout << Garner(B,M,mod) << endl; }