#br = open('b.in')

c1, c2, x, y = map(int, raw_input().strip().split())
N, M = 400, 1l << 256

def bin_search(n, d, m):
  lo, hi = 0, M
  
  for i in range(N):
    mid = (hi + lo) / 2
    c = mid - (mid / d)

    if m > 0:
      c = c - (mid / m)

    if c < n:
      lo = mid + 1
    else:
      hi = mid - 1

  return lo

r = bin_search(c1, x, 0)
r = max(r, bin_search(c2, y, x * y))

print r
