import java.util.Scanner;

/**
 * Created by Mashka on 10/28/2014.
 */
public class Solution {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int first = scanner.nextInt();
        int second = scanner.nextInt();
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        if (second > first) {
            int tmp = x;
            x = y;
            y = tmp;
            tmp = first;
            first = second;
            second = tmp;
        }
        long firstCount = 0;
        long secondCount = 0;
        int i = 1;
        int kx = 1;
        int ky = 1;
        while (true) {
            if(firstCount == first && secondCount == second){
                break;
            }
            if(i != x * kx && firstCount < first){
                firstCount++;
                i++;
                continue;
            }
            else {
                if(i == x * kx)
                    kx++;
            }

            if(i != y * ky && secondCount < second){
                secondCount++;
                i++;
                continue;
            }else{
                if(i == y * ky)
                    ky++;
            }
            i++;
        }
        System.out.println(i - 1);
    }
}
