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();
        long c = get(c1, a);
        long d = get(c2, b);
        System.out.println(Math.max(c, d));

    }

    private static long get(int c1, int a) {
        long mod = c1 % (a - 1);
        long c = c1 / (a - 1);
        c *= a;

        c += (mod == 0 ? -1 : mod);
        return c;
    }
}
