
import java.io.*;
import java.util.*;
public class B483 {
    public static void main(String args[])throws IOException
    {
        Scanner sc=new Scanner(System.in);
        long c1=sc.nextInt();
        long c2=sc.nextInt();
        long x=sc.nextInt();
        long y=sc.nextInt();
        long lo=1,hi=1000000000;
        while(hi-lo > 1)
        {
            
            long mid=(lo+hi)/2;
            long divx=mid/x,divy=mid/y,divb=mid/(x*y);
            long avail=mid-divx-divy+divb;
            long oy=divy-divb,ox=divx-divb;
            long cnt1=0,cnt2=0;
            if(oy<c1)
            {
                avail=avail-(c1-oy);
            }
            if(ox<c2)
            {
                avail=avail-(c2-ox);
            }
            if(avail<0)
                lo=mid;
            else
                hi=mid;
            //System.out.println(lo+" "+hi+" "+avail+" "+ox+" "+oy);
        }
        System.out.println(lo+1);
    }

}
