#include <bits/stdc++.h>
using namespace std;
const int N = 1e9 + 7;
int cnt1, cnt2, x, y;
bool check(int v) {
  int Re = v / (x * y);
  bool FF = false;
  if (cnt1 + cnt2 + Re <= v)
    FF |= true;
  else
    return FF;
  Re = v / x;
  if (cnt1 + Re <= v)
    FF & true;
  else
    return false;
  Re = v / y;
  if (cnt2 + Re <= v)
    return FF && true;
  else
    return false;
}
int main() {
  cin >> cnt1 >> cnt2 >> x >> y;
  long long l = 0, r = N * 2, ans = 0;
  while (l <= r) {
    long long mid = (l + r * 1LL) / 2;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << endl;
}
