a = map(int, raw_input().split())
c = max(a[0], a[1])
counter1 = 0
counter2 = 0
i = 0
if c == a[0]:
    while counter1 < a[0]:
        if i % a[2] != 0:
            counter1 += 1
        elif i % a[3] != 0:
            counter2 += 1
        i += 1 
    while counter2 < a[1]:
        if i % a[3] != 0:
            counter2 += 1
        i += 1           
else:
    while counter1 < a[0]:
        if i % a[3] != 0:
            counter2 += 1
        elif i % a[2] != 0:
            counter1 += 1
        i += 1
    while counter2 < a[1]:
        if i % a[3] != 0:
            counter2 += 1
        i += 1           
print i - 1           