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

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int cnt1 = s.nextInt(), cnt2 = s.nextInt();
        long x = s.nextInt(), y = s.nextInt();
        long left = Math.min(x * cnt1, y * cnt2), right = x * cnt1 + y * cnt2;
        while (left < right) {
            long mid = (left + right) / 2;
            if (mid - mid / x >= cnt1 && mid - mid / y >= cnt2
                && mid - mid / (x * y) >= cnt1 + cnt2) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        System.out.println(left);
    }
}
