#include<bits/stdc++.h>
using namespace std;
long long n,m,a[105],b[105],c[55],i;
long long _gcd(long long a,long long b){
long long i;
for(i=max(a,b);i>=1;i--){
if(a%i==0&&b%i==0){
return i;
}
}
return 0;
}
void chu(long long x1,long long x2){
long long xx=_gcd(x1,x2);
x1=x1/xx;x2=x2/xx;
}
int main(){
freopen("fenshu.in","r",stdin);
freopen("fenshu.out","w",stdout);
cin>>n>>m;
for(i=1;i<=n;i++) cin>>a[i]>>b[i];
for(i=1;i<=m;i++) cin>>c[i];
for(i=n;i>=1;i--){
int xx=_gcd(a[i-1]*b[i]+a[i]*b[i-1],b[i-1]*b[i]),x=a[i-1]*b[i]+a[i]*b[i-1],y=b[i-1]*b[i];
a[i-1]=x/xx;b[i-1]=y/xx;
}
for(i=1;i<=m;i++){
chu(a[1],c[i]);
}
cout<<a[1]<<" "<<b[1];
return 0;
}