# 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]+neg
    if x[3]<=p:
        print s
        test_failed=False
if test_failed:
    print s+1
# print "asd"

