#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
bool check(long long mid) {
  long long xx = mid - mid / x;
  long long yy = mid - mid / y;
  long long zz = mid / (x * y);
  if (xx < a || yy < b) return false;
  if (mid - zz >= a + b) return true;
  return false;
}
int main() {
  scanf("%I64d%I64d%I64d%I64d", &a, &b, &x, &y);
  long long l = 0, r = 1e10;
  while (l + 1 < r) {
    long long mid = l + r >> 1;
    if (check(mid)) {
      r = mid;
    } else
      l = mid;
  }
  printf("%I64d\n", r);
}
