#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, x, y, z = 0;
  cin >> a >> b >> x >> y;
  long long low = 1, high = 2000000000000000000;
  long long ans = high;
  while (low <= high) {
    long long mid = (low + high) / 2;
    long long fx = mid / y - mid / (x * y);
    long long fy = mid / x - mid / (x * y);
    long long fb = mid - (fx + fy + mid / (x * y));
    fb -= max(a - fx, z) + max(b - fy, z);
    if (fb < z)
      low = mid + 1;
    else if (fb >= z)
      ans = min(ans, mid), high = mid - 1;
  }
  cout << ans << endl;
}
