#include <stdio.h>
#include <conio.h>

typedef long long ll;

ll kqua(ll cnt1, ll cnt2, ll x, ll y)
{
    ll L = 1, R = 1e18, mid, count1, count2;
    while (L < R)
    {
        mid = (L + R) / 2;
        count1 = mid - mid / x;
        count2 = mid - mid / y;
        if (count1 >= cnt1 && count2 >= cnt2 && count1 + count2 - mid / (x*y) >= cnt1 + cnt2)
            R = mid-1;
        else
            L = mid + 1;
    }
    return L;
}

int main()
{
    ll cnt1, cnt2, x, y;
    scanf("%I64d %I64d %I64d %I64d", &cnt1, &cnt2, &x, &y);
    printf("%I64d", kqua(cnt1, cnt2, x, y));
  
    return 0;
}