cnt1, cnt2, x, y = map(int, input().split())

l = 0
r = (cnt1 // (x - 1) + 1) * x + (cnt2 // (y - 1) + 1) * y + 5

while r - l != 1:
    m = l + (r - l) // 2
    t_cnt1 = m // x * (x - 1) + m % x
    t_cnt2 = m // y * (y - 1) + m % y

    if t_cnt1 >= cnt1 and t_cnt2 >= cnt2 and t_cnt1 + t_cnt2 - m // (x * y) >= cnt1 + cnt2:
        r = m
    else:
        l = m

print(r)
