
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class R275D2B {

    public static void main(String args[]) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        String[] words;
        line = br.readLine();
        words = line.split(" ");
        long cnt1 = Long.parseLong(words[0]);
        long cnt2 = Long.parseLong(words[1]);
        long x = Long.parseLong(words[2]);
        long y = Long.parseLong(words[3]);

        long l = 1;
        long r = 1000000000000000000L;
        long m = 0;
        while (true) {
            m = (l + r) / 2;
            long c1 = cnt1;
            long c2 = cnt2;
            long none = m / (x * y);
            long f1only = m / y - none;
            long f2only = m / x - none;
            long both = m - none - f1only - f2only;
            c1 -= f1only;
            c1 = Math.max(c1, 0);
            c2 -= f2only;
            c2 = Math.max(c2, 0);
            if (both < c1 + c2) {
                l = m;
            } else if (both > c1 + c2) {
                r = m;
            } else if (both == c1 + c2) {
                break;
            }
        }
        System.out.println(m);
    }

}
