#include <bits/stdc++.h>
using namespace std;
int n;
struct node{
string a, b;
}q[10005];
string Max(string s1, string s2){
if(s1.size() > s2.size()) return s1;
if(s1.size() < s2.size()) return s2;
else{
for(int i = 0;i < s1.size();i ++){
if(s1[i] - '0' > s2[i] - '0'){
return s1;
}
if(s1[i] - '0' < s2[i] - '0'){
return s2;
}
}
}
return s2;
}
string Max2(string s1, string s2)
{
if(s1.size() > s2.size()) return s1;
if(s1.size() < s2.size()) return s2;
else{
for(int i = 0;i < s1.size();i ++)
{
if(s1[i] - '0' > s2[i] - '0')
{
return s1;
}
if(s1[i] - '0' < s2[i] - '0')
{
return s2;
}
}
}
return "---";
}
void cpy(int x[], int y[], int offset)
{
for(int i = 1;i <= x[0];i ++)
{
y[i + offset] = x[i];
}
y[0] = x[0] + offset;
}
bool check(int x[], int y[])
{
if(x[0] == y[0])
{
for(int i = 1;i <= x[0]; i ++)
{
if(x[i] > y[i])
{
return true;
}
if(x[i] < y[i])
{
return false;
}
}
}
return true;
}
void sub(int x[], int y[])
{
for(int i = x[0];i >= 1;i --)
{
if(x[i] < y[i])
{
x[i] = x[i] + 10;
x[i - 1] = x[i - 1] - 1;
}
x[i] = x[i] - y[i];
}
}
const int MAX_LEN = 2005;
string chen(string s1, string s2) {
if (s1 == "0" || s2 == "0") return "0";
int len1 = s1.size();
int len2 = s2.size();
int r[MAX_LEN * 2] = {0};
int a[MAX_LEN] = {0}, b[MAX_LEN] = {0};
for (int i = 0; i < len1; ++i)
a[i] = s1[len1-1-i] - '0';
for (int i = 0; i < len2; ++i)
b[i] = s2[len2-1-i] - '0';
for (int i = 0; i < len1; ++i) {
for (int j = 0; j < len2; ++j) {
r[i+j] += a[i] * b[j];
r[i+j+1] += r[i+j] / 10;
r[i+j] %= 10;
}
}
int pos = len1 + len2 - 1;
while (pos > 0 && r[pos] == 0) pos--;
string res;
for (int i = pos; i >= 0; --i) {
res += to_string(r[i]);
}
return res;
}
string chu(string s1, string s2)
{
int a[1000] = {0}, b[1000] = {0}, c[1000] = {0};
a[0] = s1.size();
b[0] = s2.size();
for(int i = 1;i <= a[0];i ++)
{
a[i] = s1[i - 1] - '0';
}
for(int i = 1;i <= b[0];i ++)
{
b[i] = s2[i - 1] - '0';
}
c[0] = a[0] - b[0] + 1;
int t[500] = {0};
for(int i = 1;i <= c[0]; i ++)
{
memset(t, 0, sizeof(t));
cpy(b, t, i - 1);
a[0] = t[0];
while(check(a, t) == true)
{
sub(a, t);
c[i] ++;
}
}
int pos = 1;
string ans = "";
while(c[pos] == 0 && pos < c[0]) pos ++;
for(int i = pos;i <= c[0];i ++)
{
ans += to_string(c[i]);
}
return ans;
}
bool cmp(node x, node y)
{
string k = chen(x.a, x.b);
string p = chen(y.a, y.b);
if(Max2(k, p) == "---")
{
return false;
}
if(Max2(k, p) == p)
{
return true;
}
else{
return false;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string a, b;
string ans = "0";
cin >> n;
n ++;
cin >> a >> b;
q[0].a = a;
q[0].b = b;
for(int i = 1;i < n;i ++){
cin >> q[i].a >> q[i].b;
}
sort(q + 1, q + n, cmp);
for(int i = 1;i < n;i ++){
string c = "1";
for(int j = 0;j < i;j ++){
c = chen(c, q[j].a);
}
string l = chu(c, q[i].b);
ans = Max(ans, l);
}
cout << ans;
return 0;
}