#include <bits/stdc++.h>
using namespace std;
long long int c1, c2, x, y;
bool solve(long long int v) {
  long long int a, b, nab, ab, aa, bb;
  a = v / x;
  b = v / y;
  ab = v / (x * y);
  a -= ab;
  b -= ab;
  v = v - a - b - ab;
  aa = max(0LL, c1 - b);
  bb = max(0LL, c2 - a);
  return (v >= (aa + bb));
}
int main() {
  long long int ans = 0;
  cin >> c1 >> c2 >> x >> y;
  long long int l = 1, r = 1e17;
  while (l <= r) {
    long long int m = l + (r - l) / 2;
    if (solve(m)) {
      ans = m;
      r = m - 1;
    } else {
      l = m + 1;
    }
  }
  cout << ans;
}
