#include <bits/stdc++.h>
long long int cnt1, cnt2, x, y;
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
}
int judge(long long int n) {
  if (cnt1 <= (n - n / x) && cnt2 <= (n - n / y) &&
      (cnt1 + cnt2) <= (n - n / lcm(x, y)))
    return 1;
  else
    return 0;
}
int main() {
  long long int low, high, mid;
  scanf("%I64d %I64d %I64d %I64d", &cnt1, &cnt2, &x, &y);
  low = 1;
  high = 2000000000;
  while (low < high) {
    mid = low + (high - low) / 2;
    if (judge(mid) == 1)
      high = mid;
    else
      low = mid + 1;
  }
  printf("%I64d\n", high);
  return 0;
}
