import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int a=sc.nextInt();
        int b=sc.nextInt();
        int x=sc.nextInt(),y=sc.nextInt();
        HashSet<Integer> hs=new HashSet<>();
        if(a>=b){
            int count=0;
            for(int i=1;i<=1e9;i++){
                if(i%x!=0){
                    hs.add(i);
                    count++;
                    if(count==a){
                        a=i;
                        break;
                    }
                }
            }
            count=0;
            for(int i=1;i<=1e9;i++){
                if(!hs.contains(i) && i%y!=0){
                    count++;
                    if(count==b){
                        b=i;
                        break;
                    }
                }
            }
        }
        else{
            int count=0;
            for(int i=1;i<=1e9;i++){
                if(i%y!=0){
                    count++;
                    if(count==b){
                        b=i;
                        break;
                    }
                }
            }
            count=0;
            for(int i=1;i<=1e9;i++){
                if(!hs.contains(i) && i%x!=0){
                    hs.add(i);
                    count++;
                    if(count==a){
                        a=i;
                        break;
                    }
                }
            }
        }
        System.out.println(Integer.max(a,b));
    }
}

class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new
                InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}