#include <bits/stdc++.h>
using namespace std;
long long c1, c2, x, y, nX, nY;
long long minim(long long i, long long j) {
  if (i > j) return i;
  return j;
}
int main() {
  cin >> c1 >> c2 >> x >> y;
  long long lo = 1, hi = 10000000000, mid, sol = 10000000000;
  for (int i = 0; i < 50; i++) {
    mid = (lo + hi) / 2;
    nX = mid / x;
    nY = mid / y;
    long long t1 = c1, t2 = c2;
    t1 = minim(0, t1 - nY);
    t2 = minim(0, t2 - nX);
    long long midT = mid;
    midT -= (nX + nY);
    if (midT >= t1 + t2) {
      sol = mid;
      hi = mid;
    } else
      lo = mid + 1;
  }
  cout << mid;
  return 0;
}
