#include <bits/stdc++.h>
using namespace std;
bool valid(long long v, long long cnt1, long long cnt2, int x, int y) {
  long long xy = x * y;
  long long cx = v / x;
  long long cy = v / y;
  long long cxy = v / xy;
  cnt1 = max(0LL, cnt1 - cy);
  cnt2 = max(0LL, cnt2 - cx);
  v = max(0LL, v - cxy - cy - cx);
  return v >= cnt1 + cnt2;
}
int main(int argc, char const* argv[]) {
  int cnt1, cnt2, x, y;
  scanf("%d %d", &cnt1, &cnt2);
  scanf("%d %d", &x, &y);
  long long lo = 1;
  long long hi = 3000000010;
  for (int i = 0; i < 42; ++i) {
    long long mid = (lo + hi) >> 1LL;
    if (valid(mid, cnt1, cnt2, x, y))
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << lo << "\n";
  return 0;
}
