#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int cnt1, cnt2, x, y;
bool f(long long val) {
  long long prc1, prc2, prct;
  prc1 = val / x;
  prc2 = val / y;
  prct = val / (x * y);
  bool enough1 = val - prc1 >= cnt1;
  bool enough2 = val - prc2 >= cnt2;
  bool enought = val - prct >= (cnt1 + cnt2);
  return enough1 && enough2 && enought;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> cnt1 >> cnt2 >> x >> y;
  long long Hi = 2e10, Lo = 0;
  long long s = 1;
  while (1) {
    long long jury = 1LL * (Hi + Lo) / 2;
    if (f(jury))
      Hi = jury;
    else
      Lo = jury;
    if (Hi == Lo || Hi - Lo == 1) break;
  }
  cout << Hi;
}
