#include <bits/stdc++.h>
using namespace std;
long long cnt1, cnt2, x, y;
bool check(long long val) {
  long long nt1 = val / x;
  nt1 = val - nt1;
  long long nt2 = val / y;
  nt2 = val - nt2;
  if (cnt1 > nt1) return false;
  if (cnt2 > nt2) return false;
  long long give1 = val / y;
  if (give1 >= cnt1) return true;
  long long give2 = val / x;
  if (give2 >= cnt2) return true;
  long long temp = val / x + val / y;
  temp -= (val / (x * y));
  temp = val - temp;
  cnt1 -= give1;
  cnt2 -= give2;
  if (temp >= (give1 + give2)) return true;
  return false;
}
void solve() {
  long long start = 1;
  long long end = 9000000000000000000LL;
  scanf("%lld%lld%lld%lld", &cnt1, &cnt2, &x, &y);
  while (start < end) {
    long long mid = (start + end) / 2;
    if (check(mid))
      end = mid;
    else
      start = mid + 1;
  }
  printf("%lld\n", start);
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
