#include <bits/stdc++.h>
using namespace std;
long long cnt1, cnt2, x, y;
bool check(long long q) {
  long long f = q - q / x;
  long long s = q - q / y;
  long long fs = q - q / (x * y);
  if (f < cnt1 || s < cnt2 || fs < cnt1 + cnt2)
    return false;
  else
    return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> cnt1 >> cnt2 >> x >> y;
  long long l = 1, r = 1e18;
  while (r - l - 1 > 0) {
    long long m = (r + l) / 2;
    if (!check(m))
      l = m;
    else
      r = m;
  }
  cout << r;
  return 0;
}
