__author__ = '-'

inData = input().strip().split(" ")
c1,c2,x,y = int(inData[0]),int(inData[1]),int(inData[2]),int(inData[3])

arvud1 = []
arvud2 = []
if c1>c2:
    n = 1
    while (len(arvud1)<c1):
        if n%x != 0:
            arvud1.append(n)
        n += 1
    print(arvud1[-1])
else:
    n = y
    while (len(arvud1)<c1):
        if n%x != 0:
            arvud1.append(n)
        n += 1
    n = 1
    while (len(arvud2)<c2):
        if n %y != 0 and n not in arvud1:
            arvud2.append(n)
        n += 1
    print(max(arvud1[-1],arvud2[-1]))
