#include <bits/stdc++.h>
using namespace std;
long long cnt1, cnt2, x, y, bc;
int Check(long long v) {
  long long g1 = v / y;
  long long g2 = v / x;
  long long g = v - (g1 + g2 - v / bc);
  if (v - g2 < cnt1) return 0;
  if (g1 >= cnt1) return (g2 + g >= cnt2);
  return (g2 + g + g1 - cnt1 >= cnt2);
}
int main() {
  cin >> cnt1 >> cnt2 >> x >> y;
  bc = x * y;
  long long l = 1;
  long long r = 1e15;
  long long m, res = 0;
  while (l <= r) {
    m = (l + r) / 2;
    if (Check(m))
      res = m, r = m - 1;
    else
      l = m + 1;
  }
  cout << res;
  return 0;
}
