#include <bits/stdc++.h>
using namespace std;
long long mod(long long a, long long b) {
  long long ans;
  if (b == 0)
    return -1;
  else {
    ans = (a < 0 ? mod(((a % b) + b), b) : a % b);
  }
  return ans;
}
void solve() {
  long long c1, c2, x, y;
  cin >> c1 >> c2 >> x >> y;
  long long L = c1 + c2, R = 1000000000000000;
  while (L < R) {
    long long v = L + (R - L) / 2;
    long long a = c1, b = c2;
    long long both = v / (x * y);
    long long f1 = v / x;
    long long f2 = v / y;
    a -= f2;
    b -= f1;
    long long rem = v - f1 - f2 + both;
    if (a < 0) a = 0;
    if (b < 0) b = 0;
    if (a + b <= rem)
      R = v;
    else
      L = v + 1;
  }
  cout << R << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
