#include <bits/stdc++.h>
using namespace std;
int main() {
  long long cnt1, cnt2, x, y;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> cnt1 >> cnt2 >> x >> y;
  long long ans1 = ((cnt1) / (x - 1)) * x +
                   (((cnt1) % (x - 1) == 0) ? -1 : (cnt1 % (x - 1)));
  long long ans2 = ((cnt2) / (y - 1)) * y +
                   (((cnt2) % (y - 1) == 0) ? -1 : (cnt2 % (y - 1)));
  long long sad = -1, cnt = -1, sadc = -1;
  if (cnt1 < cnt2) {
    cnt = cnt2;
    sad = x;
    sadc = cnt1;
  } else {
    cnt = cnt1;
    sad = y;
    sadc = cnt2;
  }
  long long ans = max(ans1, ans2);
  long long tans = ans;
  long long sub = (ans) / (x * y);
  assert(ans >= cnt);
  ans -= cnt;
  ans -= sub;
  if (ans >= sadc) {
    cout << tans << "\n";
    return 0;
  } else
    sadc -= ans;
  while (1) {
    tans += 1;
    ans += 1;
    sadc--;
    if ((tans % sad) == 0) sadc += 1;
    if (sadc == 0) break;
  }
  cout << tans << "\n";
  return 0;
}
