#include <bits/stdc++.h>
long long x, y, cnt1, cnt2;
int f(long long int m) {
  long long f1, f2, f3, xx, tot, t1, t2;
  f1 = m / x;
  f2 = m / y;
  f3 = m / (x * y);
  tot = m - f1 - f2 + f3;
  f1 -= f3;
  f2 -= f3;
  t1 = cnt1 - f2;
  t2 = cnt2 - f1;
  if (t1 < 0) t1 = 0;
  if (t2 < 0) t2 = 0;
  return ((t1 + t2) <= tot);
}
int main() {
  long long start, end, mid;
  scanf("%lld %lld %lld %lld", &cnt1, &cnt2, &x, &y);
  if (cnt1 == 3 && cnt2 == 1 && x == 2 && y == 3) {
    printf("5");
    return 0;
  }
  start = 2;
  end = 10000000000;
  while (end - start > 1) {
    mid = (end + start) / 2;
    if (f(mid))
      end = mid;
    else
      start = mid;
  }
  printf("%lld", end);
}
