#include <bits/stdc++.h>
using namespace std;
bool ar[1000000];
bool call(long long n, long long x, long long y, long long c1, long long c2) {
  long long n1 = n / x;
  long long n2 = n / y;
  long long cm = n / (x * y);
  n1 = (n - n1 - cm);
  n2 = (n - n2 - cm);
  if ((n1 >= c1) && (n2 >= c2)) {
    return true;
  } else
    return false;
}
int main() {
  long long cnt1, cnt2, x, y;
  cin >> cnt1 >> cnt2 >> x >> y;
  long long int ans = (cnt1 + cnt2);
  if (ans < min(x, y)) cout << ans;
  bool f;
  while (1) {
    long long n1 = ans / x;
    long long n2 = ans / y;
    long long cm = ans / (x * y);
    n1 = (ans - n1 - cm);
    n2 = (ans - n2 - cm);
    if (n1 < cnt1)
      ans += (cnt1 - n1);
    else
      ans += (cnt2 - n2);
    bool f = call(ans, x, y, cnt1, cnt2);
    if (f) {
      break;
    }
  }
  cout << ans;
  return 0;
}
