import javax.print.attribute.IntegerSyntax;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class SolveProblem {
    private BufferedReader in;
    private PrintWriter out;

    SolveProblem() {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter(new FileWriter("output.txt"),true);
            solve();
        } catch (Exception e) {
            e.printStackTrace();
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
        } finally {
            try {
                in.close();
            } catch (IOException e) {

            }
            out.close();
        }
    }
    StringTokenizer st;
    String nextToken() {
        while (st == null || !st.hasMoreTokens())
            try {
                st = new StringTokenizer(in.readLine());
            } catch (IOException e) {

            }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.valueOf(nextToken());
    }
    long nextLong() {
        return Long.valueOf(nextToken());
    }

    public void solve() {
        int cnt1 = nextInt();
        int cnt2 = nextInt();
        int x = nextInt();
        int y = nextInt();
        if (cnt1 > cnt2) {
            int k = 0;
            int i = 1;
            Set<Integer> set = new HashSet<>();
            while(k < cnt1) {
                if (i % x > 0) {
                    k++;
                    set.add(i);
                }
                i++;
            }
            int j = 0;
            k = 0;
            while(k < cnt2) {
                if (j % y > 0 && !set.contains(j)) {
                    k++;
                    set.add(j);
                }
                j++;
            }
            out.print(Math.max(i,j)-1);
        } else {
            int k = 0;
            int i = 1;
            Set<Integer> set = new HashSet<>();
            while(k < cnt2) {
                if (i % y > 0) {
                    k++;
                    set.add(i);
                    System.out.println(i);
                }
                i++;
            }
            int j = 0;
            k = 0;
            while(k < cnt1) {
                if (j % x > 0 && !set.contains(j)) {
                    k++;
                    set.add(j);
                }
                j++;
            }
            out.print(Math.max(i,j)-1);
        }
    }

    public static void main(String[] args) {
        new SolveProblem();
    }
}