#include <bits/stdc++.h>
using namespace std;
const double eps = 1E-8;
const int dx4[4] = {1, 0, 0, -1};
const int dy4[4] = {0, -1, 1, 0};
const int inf = 0x3f3f3f3f;
const int N = 1E5 + 7;
int cnt1, cnt2, x, y;
inline long long check(long long num) {
  long long cntx = num / x, cnty = num / y, _ = num / (x * y), ote, ansx, ansy,
            f_x, f_y;
  ote = num - cntx - cnty + _;
  ansx = cnty - _, ansy = cntx - _;
  f_x = cnt1 - ansx >= 0 ? cnt1 - ansx : 0;
  f_y = cnt2 - ansy >= 0 ? cnt2 - ansy : 0;
  if (f_x + f_y <= ote)
    return 1;
  else
    return 0;
}
int main() {
  scanf("%d%d%d%d", &cnt1, &cnt2, &x, &y);
  long long l = 1, r = 1e18;
  long long ans = 0;
  while (l < r) {
    long long mid = (l + r) >> 1;
    if (check(mid)) {
      r = mid;
      ans = mid;
    } else {
      l = mid + 1;
    }
  }
  printf("%lld\n", ans);
}
