import sys


def read_input():

	for line in sys.stdin:
		yield line


def solve(c1, c2, x, y):
	if c1 < c2:
		c1, c2 = c2, c1
		x, y = y, x	
	i = 0
	while c1 > 0 or c2 > 0:
		i += 1
		if (i % x == 0):
			c2 -= 1
		elif (i % y == 0):
			c1 -= 1
		elif c1 > 0:
			c1 -= 1
		else:
			c2 -= 1
	return i


def main():

	for line in read_input():
		c1, c2, x, y = map(int, line.strip().split())
		print solve(c1, c2, x, y)


main()