import java.io.*;
import java.lang.*;
import java.util.*;

public class Main {
    public static Scanner cin = new Scanner (System.in);
    
    public static void main(String args[]) {
        long d1 = cin.nextLong(), d2 = cin.nextLong(), x = cin.nextLong(), y = cin.nextLong();
        long l = 1, r = (long)1000000000L, res = 0;
        while (l <= r) {
            long m = (l+r)/2;
            long t = m/(x+y), t1 = m/x, t2 = m/y, sum = t1+t2-t;
            t1 -= t; t2 -= t;
            long can = Math.max(0, d1-t2) + Math.max(0, d2-t1);
            if (can <= m-sum) {
                res = m;
                r = m-1;
            }
            else
                l = m+1;
        }
        System.out.println(res);
    }   
}