#include <bits/stdc++.h>
using namespace std;
long long needs(long long p, long long count) {
  if (p == 2) return count * p - 1;
  long long chunks = count / (p - 1);
  long long extra = count % (p - 1);
  return chunks * p + extra;
}
long long maxi(long long a, long long b, long long c) {
  if (a >= b and a >= c)
    return a;
  else if (b >= a and b >= c)
    return b;
  return c;
}
int main() {
  long long c1, c2, x, y;
  cin >> c1 >> c2 >> x >> y;
  long long answer = maxi(c1 + c2, needs(x, c1), needs(y, c2));
  while (answer - answer / (x * y) < c1 + c2) {
    answer += c1 + c2 - answer + answer / (x * y);
  }
  cout << answer << endl;
  return 0;
}
