#include<bits/stdc++.h>
using namespace std;
long long n,m;
long long a,b;
long long ans,bns;
long long gcd(long long x,long long y)
{
if(y==0)
{
return x;
}
return gcd(y,x%y);
}
long long lcm(long long x,long long y)
{
return x*y/gcd(x,bns);
}
void so()
{
long long a=1,b=0;
long long l=max(ans,bns);
for(long long i=1; i<=l; i++)
{
for(long long j=1; j<=l; j++)
{
if((double)i/j>=(double)ans/bns&&(double)i/j<(double)a/b)
{
a=i;
b=j;
}
}
}
ans=a;
bns=b;
}
int main()
{
freopen("fenshu.in","r",stdin);
freopen("fenshu.out","w",stdout);
cin>>n>>m;
cin>>a>>b;
ans=a;
bns=b;
for(long long i=1; i<n; i++)
{
cin>>a>>b;
if(b==bns)
{
ans+=a;
}
else
{
long long atmp=lcm(b,bns)/bns;
long long btmp=lcm(b,bns)/b;
bns*=atmp;
ans*=atmp;
b*=btmp;
a*=btmp;
ans+=a;
}
so();
}
for(long long j=0; j<m; j++)
{
cin>>a;
b=1;
ans*=b;
bns*=a;
so();
}
if(ans==bns)
{
cout<<ans;
}
else
{
cout<<ans<<" "<<bns;
}
return 0;
}