#br = open('b.in')

c1, c2, x, y = map(int, raw_input().strip().split())
N, M = 200, 1e18

lo, hi = 0, M

for i in range(N):
  mid = (hi + lo) / 2
  div = mid / x
  lef = mid - div

  if lef < c1:
    lo = mid
  else:
    hi = mid

lo = hi
hi = M

for i in range(N):
  mid = (hi + lo) / 2
  div = mid / x
  uni = mid / (x * y)
  lef = mid - div - uni

  if lef < c2:
    lo = mid
  else:
    hi = mid

print lo 
