from sys import stdin
debug = False

try :
  import os
  if os.environ['COMPUTERNAME'] == 'KRUEGER-PC':
    debug = True
except KeyError:
  pass  

def debug_print(*foo):
  if debug:
    print (foo)

debug_print("debug active")    

def print_array(res, size):
  if size:
    print(len(res))
  print(" ".join(map(str, res)))

def input_int_tuple():
  return tuple([ x for x in map(int, stdin.readline().split())])

def input_int_array(size=True):
  if size:
    #read 
    values = stdin.readline().split()
    assert(len(values) == 1)
  return [x for x in map(int, stdin.readline().split())]

def input_string():
  return stdin.readline().strip()



def problem():
  c1, c2, x, y = input_int_tuple()
  r1 = c1
  while r1 - r1 // x <c1:    
    r1 += c1 - r1 + r1 // x

   
  have =  r1 //x -  r1 // (x*y)
  cx2 = c2 - have
  
  r2 = r1 + cx2
  while r2-r1 - (r2-r1) // y <cx2:    
      r2 += cx2 -(r2-r1 - (r2-r1) // y)
  
  
  while True:
    b1 = r2 //x
    b2 = r2 //y
    b12 = r2 // (x*y)
    both = r2 - b1 - b2 + b12
    cx1 = max(0, c1 - b2+ b12)
    cx2 = max(0, c2 - b1+b12)
    if not cx2 + cx1 <= both :    
      break
    r2 -= 1

  print r2+ 1




  


problem()


#print_array(problem(), False)

#xx = input_string()
