def calcV(h, D):
    pV = 0
    V = h
    while (V-pV)//D != 0:
        t = V
        V = V + (V-pV)//D
        pV = t
    if V%D == 0:
        V += 1
    return V

def nburacos(t, x, y):
  return t//y - t//(x*y)


cnt1, cnt2, x, y = [int(x) for x in input().strip().split()]
h = calcV(cnt1 + cnt2, x*y)
p1 = calcV(cnt1, x)
p2 = calcV(cnt2, y)

if nburacos(p1, x, y) >= cnt2:
    print(p1)
if nburacos(p2, y, x) >= cnt1:
    print(p2)
else:
    print(h)

# 1481917467116