#include <bits/stdc++.h>
using namespace std;
using Long = long long;
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Long cnt1, cnt2, x, y;
  cin >> cnt1 >> cnt2 >> x >> y;
  Long minAns = 1;
  Long maxAns = 10000000000000ll;
  Long ans = maxAns;
  while (minAns <= maxAns) {
    Long currAns = (minAns + maxAns) / 2ll;
    Long multiplesX = currAns / x;
    Long multiplesY = currAns / y;
    Long intersectionXY = currAns / (x * y);
    Long freeBoth = currAns - (multiplesX + multiplesY - intersectionXY);
    Long aux1 = max(0ll, cnt1 - (currAns - multiplesX - freeBoth));
    Long aux2 = max(0ll, cnt2 - (currAns - multiplesY - freeBoth));
    if (aux1 > 0) {
      if (aux1 <= freeBoth) aux1 = 0;
      freeBoth -= aux1;
    }
    if (aux2 > 0) {
      if (aux2 <= freeBoth) aux2 = 0;
    }
    if (aux1 <= 0 and aux2 <= 0) {
      maxAns = currAns - 1;
      ans = currAns;
    } else
      minAns = currAns + 1;
  }
  cout << ans << "\n";
  return 0;
}
