import java.lang.*;
import java.util.*;
public class eq
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int c1 = sc.nextInt();
        int c2 = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int i=1;
        while(c1>0 || c2>0)
        {
            int a = i%x;
            int b = i%y;
            if(a*b>0)
            {
                if(c1*c2>0)
                    {
                        if(c1>c2){c1--;}
                        else {c2--;}
                    }
                else if(c1>0)
                    {
                        c1--;
                    }
                else c2--;  
            }
            else if(a>0)
            {
                if(c1>0){c1--;}
            }
            else
            {
                if(c2>0){c2--;}
            }
            i++;
        }
        System.out.println(i-1);
}
}   