#include <bits/stdc++.h>
using namespace std;
int cnt1, cnt2, x, y;
int chk(long long int v) {
  long long int f, s;
  f = v / x;
  s = v / y;
  long long both = v / (1ll * x * y);
  long long rem = v - v / x - v / y + both;
  f -= both;
  s -= both;
  long long tf, ts;
  tf = cnt1 - s;
  ts = cnt2 - f;
  tf = max(0ll, tf);
  ts = max(0ll, ts);
  return (tf + ts <= rem);
}
int main() {
  scanf("%d %d %d %d", &cnt1, &cnt2, &x, &y);
  long long int l = 0;
  long long int r = (int)(1e18);
  long long int mid;
  while (l < r) {
    mid = (l + r) / 2;
    if (chk(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%lld\n", l);
  return 0;
}
