#include <bits/stdc++.h>
using namespace std;
int cnt1, cnt2, x, y;
int ans1, ans2, ans;
long long maxn;
long long l, r;
int main() {
  while (scanf("%d %d %d %d", &cnt1, &cnt2, &x, &y) != EOF) {
    l = 1;
    r = 1e15;
    while (l < r) {
      long long mid = l + (r - l) / 2;
      long long a = mid / x;
      long long b = mid / y;
      long long c = mid / (x * y);
      if ((mid - a) >= cnt1 && mid - b >= cnt2 && (mid - c) >= cnt1 + cnt2) {
        r = mid;
      } else
        l = mid + 1;
    }
    printf("%lld\n", l);
  }
  return 0;
}
