#include <bits/stdc++.h>
using namespace std;
long long cn1, cn2, x, y;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
bool check(long long n, long long n1, long long n2) {
  long long g = (x * y) / gcd(x, y);
  n1 -= n / y - n / g;
  n2 -= n / x - n / g;
  n -= n / x + n / y - n / g;
  if (n1 < 0) n1 = 0;
  if (n2 < 0) n2 = 0;
  if (n >= n1 + n2) {
    return true;
  } else {
    return false;
  }
}
int main() {
  cin >> cn1 >> cn2 >> x >> y;
  long long l = 0, r = 1000000000;
  long long mid;
  long long ans = 0;
  while (l <= r) {
    mid = (l + r) / 2;
    if (check(mid, cn1, cn2)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans;
}
