#include <bits/stdc++.h>
int cal(int a, int b) { return a - a / b; }
int main() {
  int cnt1, cnt2, x, y;
  scanf("%d %d %d %d", &cnt1, &cnt2, &x, &y);
  int l = 1, r = 2e9;
  while (l < r) {
    int mid = l + (r - l) / 2;
    if (cnt1 <= cal(mid, x) && cnt2 <= cal(mid, y) &&
        cnt1 + cnt2 <= cal(mid, x * y))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", r);
}
