#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);
long long cnt1,cnt2,x,y,cnt33;
cin>>cnt1>>cnt2>>x>>y;
cnt33=cnt1+cnt2;
 long long l=1,r=100000000000000;
 long long mid=1,bestmid=100000000000001,z;
 z=(x*y)/__gcd(x,y);
// cout<<z<<endl;
 while(l<=r){
 	mid=(l)+(r-l)/2;
 	//cout<<l<<" "<<r<<endl;
 	
 ///	cout<<mid<<" "<<mid-(mid/z)<<endl;
 	
 	long long cnt3=(mid/x)-(mid/z);
 	long long cnt4=(mid/y)-(mid/z);
   long long n=mid-((mid/x)+(mid/y)-(mid/z));
 	if(cnt3<cnt2){
 		cnt3+=min(cnt2-cnt3,n);
 		n-=min(cnt2-cnt3,n);
 	
 	}
 		if(cnt4<cnt1){
 		cnt4+=min(cnt1-cnt4,n);
 		n-=min(cnt1-cnt4,n);
 	
 	}
 
 	 if(cnt3<cnt2||cnt4<cnt1){
 		l=mid+1;
 	}
 	else{
 		if(bestmid>mid)bestmid=mid;
 		r=mid-1;
 	}
 }
 cout<<bestmid<<endl;
	return 0;
}