#include <bits/stdc++.h>
using namespace std;
unsigned long long recur_gcd(unsigned long long a, unsigned long long b) {
  return a % b == 0 ? b : recur_gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  long long cnt1, cnt2, x, y;
  cin >> cnt1 >> cnt2 >> x >> y;
  long long upper = 1000000000000;
  long long lower = cnt1 + cnt2;
  while (lower < upper) {
    long long m = lower + (upper - lower) / 2;
    long long aux1, aux2, aux3, aux4, cnt11 = cnt1, cnt22 = cnt2;
    aux1 = m / x;
    aux2 = m / y;
    aux3 = m / (x * y);
    aux4 = m - aux1 - aux2 + aux3;
    cnt11 -= aux2 + aux3;
    cnt22 -= aux1 + aux3;
    assert(x != y);
    long long sum = (cnt11 >= 0 ? cnt11 : 0) + (cnt22 >= 0 ? cnt22 : 0);
    if (aux4 >= sum) {
      upper = m;
    } else
      lower = m + 1;
  }
  cout << lower;
  return 0;
}
