#include <bits/stdc++.h>
using namespace std;
long long cnt1, cnt2, x, y;
bool call(long long n) {
  long long n1 = n / x;
  long long n2 = n / y;
  long long cm = n / (x * y);
  n1 = (n - n1);
  n2 = (n - n2);
  if ((n1 >= cnt1) && (n2 >= cnt2) && (n1 + n2 - cm) >= (cnt1 + cnt2)) {
    return true;
  } else
    return false;
}
long long bis(long long l, long long h) {
  if (l == h) return l;
  long long mid = (l + h) >> 1;
  if (call(mid))
    bis(l, mid);
  else
    bis(mid + 1, h);
}
int main() {
  cin >> cnt1 >> cnt2 >> x >> y;
  cout << bis(0, 1e15);
  return 0;
}
