#include <bits/stdc++.h>
using namespace std;
long long c1, c2, x, y, forx = 0, fory = 0, both = 0, pre = 0;
bool ok(long long mid) {
  long long t1, t2;
  if (mid > pre)
    for (long long i = pre + 1; i <= mid; i++) {
      t1 = i % x;
      t2 = i % y;
      if (t1 != 0 && t2 != 0)
        both++;
      else if (t1 != 0)
        forx++;
      else if (t2 != 0)
        fory++;
      if (forx < c1) {
        if (both - (c1 - forx) >= 0) {
          if (fory < c2)
            if (both - (c1 - forx) - (c2 - fory) >= 0) return true;
          if (fory >= c2) return true;
        }
      } else if (forx >= c1) {
        if (fory < c2)
          if (both - (c2 - fory) >= 0) return true;
        if (fory >= c2) return true;
      }
    }
  else {
    for (long long i = pre; i > mid; i--) {
      t1 = i % x;
      t2 = i % y;
      if (t1 != 0 && t2 != 0)
        both--;
      else if (t1 != 0)
        forx--;
      else if (t2 != 0)
        fory--;
    }
    if (forx < c1) {
      if (both - (c1 - forx) >= 0) {
        if (fory < c2)
          if (both - (c1 - forx) - (c2 - fory) >= 0) return true;
        if (fory >= c2) return true;
      }
    } else if (forx >= c1) {
      if (fory < c2)
        if (both - (c2 - fory) >= 0) return true;
      if (fory >= c2) return true;
    }
  }
  return false;
}
int main() {
  scanf("%lld%lld%lld%lld", &c1, &c2, &x, &y);
  long long low = c1 + c2, high = c1 * x / (x - 1) + c2 * y / (y - 1), mid;
  while (low < high) {
    mid = (low + high) / 2;
    if (ok(mid))
      high = mid;
    else
      low = mid + 1;
    pre = mid;
  }
  printf("%lld\n", high);
}
