import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class FriendsAndPresents {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tok = new StringTokenizer(br.readLine());
		long c1, c2, p1, p2;
		c1 = Integer.parseInt(tok.nextToken());
		c2 = Integer.parseInt(tok.nextToken());
		p1 = Integer.parseInt(tok.nextToken());
		p2 = Integer.parseInt(tok.nextToken());
		System.out.println( solve(c1, c2, p1, p2) );
	}

	private static long solve(long c1, long c2, long p1, long p2) {
		long ok = 10_000_000_000L;
		long nok = 1;
		while (nok + 1 < ok) {
			long mid = (ok + nok) / 2;
			if ( isOk(c1, c2, p1, p2, mid) ) {
				ok = mid;
			} else {
				nok = mid;
			}
		}
		return ok;
	}

	private static boolean isOk(long c1, long c2, long p1, long p2, long v ) {
		long xy = v / (p1 * p2);
		long x = v / p1;
		long nc1 = v - x;
		if (nc1 < c1) return false;
		long y = v / p2;
		long mc = Math.min(c1, nc1);
		long d = y > mc ? y - mc : 0;
		long nc2 = v - mc - d + xy;
		return nc2 >= c2;
	}
}
