#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long rem, cnt1, cnt2, x, y, tmp;
  cin >> cnt1 >> cnt2 >> x >> y;
  rem = 0;
  if (cnt1 < cnt2) swap(cnt1, cnt2), swap(x, y);
  while (((cnt1 + rem) / x) - rem) rem += (((cnt1 + rem) / x) - rem);
  cnt1 += rem;
  cnt2 -= ((cnt1 / x) - (cnt1 / (x * y)));
  if (cnt2 <= 0) {
    cout << cnt1;
    return 0;
  }
  tmp = (((cnt1 + (x * y) - 1) / (x * y)) * (x * y));
  if (cnt2 <= (tmp - cnt1 - 1)) {
    cout << cnt1 + cnt2;
    return 0;
  }
  cnt2 -= (tmp - cnt1 - 1);
  cnt1 = tmp;
  rem = 0;
  while (((cnt2 + rem) / (x * y)) - rem)
    rem += (((cnt2 + rem) / (x * y)) - rem);
  cnt2 += rem;
  cout << cnt1 + cnt2;
  return 0;
}
