#include <bits/stdc++.h>
using namespace std;
long long cnt1;
long long cnt2;
long long x;
long long y;
long long l;
long long r;
long long mid;
int main() {
  cin >> cnt1 >> cnt2 >> x >> y;
  l = 0;
  r = 1e18;
  while (l < r) {
    mid = (l + r) / 2;
    if (mid - mid / x >= cnt1 && mid - mid / y >= cnt2 &&
        cnt1 + cnt2 <= mid - mid / (x * y))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}
