#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long oo = 1e13;
const double PI = acos(-1);
int main() {
  long long cx, cy, x, y;
  cin >> cx >> cy >> x >> y;
  long long lo = 0, hi = 1e18, ans = 0;
  while (lo <= hi) {
    long long md = (hi + lo) / 2;
    long long vl = md / (x * y), al = md - md / x - md / y + vl;
    if (al + md / y - vl >= cx && (al + md / y - vl) - cx + md / x - vl >= cy) {
      hi = md - 1;
      ans = md;
    } else
      lo = md + 1;
  }
  printf("%lld\n", ans);
}
