import math
cnt1,cnt2,x,y = map(int,raw_input().split())


def last_digit(cnt,x):
    upper = math.ceil(cnt/float((x-1)))*x
    lower = upper-x
    lower_cnt = (lower - (lower/x))
    return lower + (cnt-lower_cnt)

def solve(cnt1,cnt2,x,y):
    ans = 0
    l = last_digit(cnt1,x)
    ans = l
    #print ans
    lower = math.ceil(l/float(y)) * y
    free = lower-l-1 if lower!=l else 0
    cnt2 -= int(math.floor(l/x))
    #print cnt2,free
    if cnt2 < free:
        if cnt2 > 0:
            ans += cnt2
    else:
        ans += (free+1)
        cnt2 -= free
        ans += last_digit(cnt2,y)
    #print ans
    return int(ans)


print min(solve(cnt1,cnt2,x,y),solve(cnt2,cnt1,y,x))
    
