line = input().split()
cnt1 = int(line[0])
cnt2 = int(line[1])
x = int(line[2])
y = int(line[3])

maxNum = 100000000000

def solve(n):
    a = -1
    pot = 1
    while True:
        if pot > n:
            break
        pot *= x
        a += 1
    
    b = -1
    pot = 1
    while True:
        if pot > n:
            break
        pot *= y
        b += 1
    
    curr_cnt1 = max(0, cnt1 - b)
    curr_cnt2 = max(0, cnt2 - a)
    shared = curr_cnt1 + curr_cnt2
    counter = 0
    pot_a = x
    while True:
        pot_b = y
        if pot_a * pot_b > n:
            break
        while True:
            if pot_a * pot_b > n:
                break
            counter += 1
            pot_b *= y
        pot_a *= x
    
    remaining = n - a - b - counter
    if remaining > shared:
        return 1
    elif remaining == shared:
        return 0
    else:
        return -1

def binary_search(left, right):
    middle = (left + right) // 2
    if solve(middle) == 0:
        return middle
    elif solve(middle) == 1:
        return binary_search(left, middle - 1)
    else:
        return binary_search(middle + 1, right)

ans = binary_search(1, maxNum)
while True:
    if solve(ans - 1) == 0:
        ans -= 1
    else:
        break
print(ans)
 	 		  	 		    	  					  	 	 	