#include <bits/stdc++.h>
int main() {
  long long int ende, endx, endy;
  long long int num, sum, end;
  int cnt1, cnt2, x, y;
  scanf("%d%d%d%d", &cnt1, &cnt2, &x, &y);
  sum = 0, end = 100000000009;
  while (sum <= end) {
    num = (sum + end) / 2;
    endx = num / x, endy = num / y, ende = num / (x * y);
    if (num - ende >= cnt1 + cnt2 && num - endx >= cnt1 && num - endy >= cnt2)
      end = num - 1;
    else
      sum = num + 1;
  }
  printf("%lld\n", sum);
  return 0;
}
