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

public class p481b {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long cnt1 = sc.nextLong();
        long cnt2 = sc.nextLong();
        long x = sc.nextLong();
        long y = sc.nextLong();
        long low = 1, high = 1000000000L, mid;
        while (low < high) {
            mid = (low + high) / 2;
            if (mid - mid / x >= cnt1 && mid - mid / y >= cnt2 && mid - mid / (x * y) >= cnt1 + cnt2) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }
        System.out.println(high);
    }
}