# x = map(int,raw_input().split())
# for i in xrange(input()):
# from fractions import gcd
x = map(int,raw_input().split())
# test 1
# s = (x[0]+x[1])
# neg = s/x[2]
# pos = s-neg
# test_failed=True
# # print pos
# if x[0]<=pos:
#   # print pos
#   n = s/x[3]
#   p = s-(n-x[0])
#   # print p
#   if x[3]<=p:
#       print s
#       test_failed=False
# if test_failed:
#   print s+1
# print "asd"

# a =min(x[2],x[3])
j=1
while(True):
    if (j-(j/x[2]))>=x[0]:
        break
    j=j+1
# print j
ans=j
j=1
while(True):
    # print j
    if ((j-(j/x[3])+j/x[2])-x[0])>=x[1]:
        # print j,(j-(j/x[3])+j/x[2])
        break
    j=j+1

print max(ans,j)