# x = map(int,raw_input().split())
# for i in xrange(input()):
# from fractions import gcd
x = map(int,raw_input().split())
j=1
while(True):
    if (j-(j/x[2]))>=x[0]:
        break
    j=j+1
# print j
ans=j
j=2
while(True):
    # print j
    if (j + j/x[2] -2* j/x[3])>=x[1]:
        # print j,(j-(j/x[3])+j/x[2])
        break
    j=j+1

print max(ans,j)