__author__ = 'igormelnyk'
def search(cnt,x,l,r):
  tmp = (l+r)/2
  numberForTmp = tmp-tmp/x
  if numberForTmp==cnt:
   return (l+r)/2
  elif numberForTmp<cnt:
   return search(cnt,x,tmp+1,r)
  else:
   return search(cnt,x,l,tmp-1)

[cnt1,cnt2,x,y] = (int(x) for x in raw_input().split(' '))
if cnt2>cnt1:
    tmp  = cnt2
    cnt2 = cnt1
    cnt1 = tmp
    tmp  = x
    x    = y
    y    = tmp
N = search(cnt1,x,cnt1,cnt1*2)
cnt2 = cnt2-N/y+N/(y*x)
cnt2 = 0 if cnt2<0 else cnt2
N=N+search(cnt2,y,cnt2,cnt2*2)
print N