import java.util.Scanner;

public class B483 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int c1 = in.nextInt();
        int c2 = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int c = c1 / (a - 1) * a + ((c1) % (a - 1) == 0 ? -1 : (c1) % (a - 1));
        int d = c2 / (b - 1) * b + (c2 % (b - 1) == 0 ? -1 : (c2) % (b - 1));
        System.out.println(Math.max(c, d));

    }
}
