#include <bits/stdc++.h>
using namespace std;
long long cnt1, cnt2, x, y;
bool check(long long temp) {
  long long u = temp / x;
  long long v = temp / y;
  long long w = temp / (x * y);
  long long check1 = cnt1, check2 = cnt2;
  temp = temp - u - v + w;
  u -= w;
  v -= w;
  check1 = max(0LL, check1 - v);
  check2 = max(0LL, check2 - u);
  if (check1 + check2 <= temp) return true;
  return false;
}
int main(int argc, char const *argv[]) {
  cin >> cnt1 >> cnt2 >> x >> y;
  long long hi = 1e18, mid, lo = 1;
  while (lo < hi) {
    mid = lo + (hi - lo) / 2;
    if (check(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << mid;
  return 0;
}
