#include <bits/stdc++.h>
using namespace std;
int main() {
  int cnt1, cnt2, x, y;
  while (scanf("%d%d%d%d", &cnt1, &cnt2, &x, &y) != EOF) {
    long long left = 0, right = 0x3f3f3f3f3f3f, mid;
    while (left <= right) {
      mid = (left + right) / 2;
      if (mid - mid / (x * y) >= cnt1 + cnt2 && mid - mid / x >= cnt1 &&
          mid - mid / y >= cnt2)
        right = mid - 1;
      else
        left = mid + 1;
    }
    printf("%I64d\n", left);
  }
  return 0;
}
