#include <bits/stdc++.h>
using namespace std;
long long cnt1, cnt2, x, y, l, r, mid;
bool check(long long n) {
  long long c1 = n - n / x;
  long long c2 = n - n / y;
  long long c3 = n - n / x - n / y + n / (x * y);
  c1 -= c3;
  c2 -= c3;
  if (c1 + c3 < cnt1)
    return false;
  else {
    if (c1 >= cnt1) {
      return (c2 + c3 >= cnt2);
    } else {
      c3 -= (cnt1 - c1);
      return (c2 + c3 >= cnt2);
    }
  }
}
int main() {
  cin >> cnt1 >> cnt2 >> x >> y;
  l = 1;
  r = (cnt1 + cnt2) * x * y;
  while (l <= r) {
    mid = (l + r) / 2;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}
