#include <bits/stdc++.h>
using namespace std;
long long cnt1, cnt2, x, y;
template <typename Head>
void myprint(Head a) {
  cout << a << '\n';
}
template <typename Head, typename... Tail>
void myprint(Head a, Tail... t) {
  cout << a << ' ';
  myprint(t...);
}
bool check(long long v) {
  long long m = x * y;
  long long div1 = v / x, div2 = v / y, divboth = v / m;
  div1 -= divboth;
  div2 -= divboth;
  long long tcnt1 = max(cnt1 - div2, 0LL), tcnt2 = max(cnt2 - div1, 0LL);
  return (tcnt1 + tcnt2 <= v - div1 - div2 - divboth);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> cnt1;
  cin >> cnt2;
  cin >> x;
  cin >> y;
  long long lo = 0, hi = 1e10;
  while (lo < hi) {
    long long mid = (lo + hi) / 2;
    if (check(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << lo << '\n';
}
