
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Solution {
	public static void main(String[] args) throws IOException {
		Solution sol = new Solution();
		sol.doWork();
	}

	public void doWork() throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String[] line = reader.readLine().split(" ");
		long a1 = Long.parseLong(line[0]);
		long a2 = Long.parseLong(line[1]);
		long p1 = Long.parseLong(line[2]);
		long p2 = Long.parseLong(line[3]);
		long i1 = 1;
		List<Long> g1 = new ArrayList<Long>();
		List<Long> g2 = new ArrayList<Long>();
		List<Long> t1 = calc(a1, p1, g1);
		List<Long> t2 = calc(a2, p2, g2);
		
		for (Long x : t2){
			if (x < g1.get(g1.size() - 1)){
				g1.remove(g1.size()-1);
			}
		}
		for (Long x : t1){
			if (x < g2.get(g2.size() - 1)){
				g2.remove(g2.size()-1);
			}
		}
		System.out.println(Math.max(g1.get(g1.size() - 1), g2.get(g2.size() - 1)));
	}
	
	private List<Long> calc(long a, long p, List<Long> good){
		long i = 1;
		List<Long> t = new ArrayList<Long>();
		while ( a > 0 ){
			if ( i % p != 0 ){
				a--;
				good.add(i);
			}else {
				t.add(i);
			}
			i++;
		}
		return t;
	}

}
