#include <bits/stdc++.h>
using namespace std;
bool chk(long long cnt1, long long cnt2, int x, int y, long long k) {
  long long ndx = k / x;
  long long ndy = k / y;
  long long ndxy = k / (x * y);
  cnt1 -= ndy - ndxy;
  cnt2 -= ndx - ndxy;
  if (cnt1 < 0) cnt1 = 0;
  if (cnt2 < 0) cnt2 = 0;
  if (cnt1 + cnt2 <= k - ndx - ndy + ndxy)
    return true;
  else
    return false;
}
int main() {
  long long cnt1, cnt2;
  int x, y;
  cin >> cnt1 >> cnt2 >> x >> y;
  long long l = 2, r = (long long)1e18 + 1, min = (long long)1e18 + 2;
  while (l <= r) {
    long long m = (l + r) / 2;
    if (chk(cnt1, cnt2, x, y, m)) {
      r = m - 1;
      if (m < min) min = m;
    } else
      l = m + 1;
  }
  cout << min;
  return 0;
}
