https://www.luogu.org/problemnew/show/P1080

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
typedef __int128 lll;
const int N=10000;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
int sum[20010],ans[20010],add[20010];
struct node{
    int a,b;
    int ab;
    bool operator <(const node & S)const{
        return ab<S.ab;
    }
}e[N];
void times(int x){
    memset(add,0,sizeof(add));
    for(int i=1;i<=ans[0];i++){
        ans[i]=ans[i]*x;
        add[i+1]+=ans[i]/10;
        ans[i]%=10;
    }
    for(int i=1;i<=ans[0]+10;i++){
        ans[i]+=add[i];
        if(ans[i]>=10){
            add[i+1]+=ans[i]/10;
            ans[i]%=10;
        }
        if(ans[i]){
            ans[0]=max(ans[0],i);
        }
    }
}
void divition(int x){
    memset(add,0,sizeof(add));
    q=0;
    for(int i=ans[0];i>=1;i--){
        q*=10;
        q+=ans[i];
        add[i]=q/x;
        if(!add[0]&&add[i]){
            add[0]=i;
        }
        q%=x;
    }
}
bool compare(){
    if(sum[0]==add[0]){
        for(int i=ans[0];i>=1;i--){
            if(sum[i]<add[i])return 1;
            if(sum[i]>add[i])return 0;
        }
    }
    if(sum[0]<add[0])return 1;
    if(sum[0]>add[0])return 0;
    return 0;
}
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    scanf("%d",&n);
    for(int i=0;i<=n;i++){
        scanf("%d%d",&e[i].a,&e[i].b);
        e[i].ab=e[i].a*e[i].b;
    }
    sort(e+1,e+n+1);
    ans[0]=1;
    ans[1]=1;
    for(int i=1;i<=n;i++){
        times(e[i-1].a);
        divition(e[i].b);
        if(compare()){
            mempcpy(sum,add,sizeof(sum));
        }
    }
    for(int i=sum[0];i>=1;i--){
        cout << sum[i];
    }
    cout << endl;
    //cout << "Hello world!" << endl;
    return 0;
}