#include <bits/stdc++.h>
using namespace std;
long long cnt1, cnt2, x, y;
long long L, R, mid, ans;
long long A, B, A_B, Ra, Rb, LAS;
long long q, p;
int main() {
  cin >> cnt1 >> cnt2 >> x >> y;
  q = cnt1;
  p = cnt2;
  L = 1;
  R = 1LL << 60;
  for (int i = 1; i <= 100; ++i) {
    if (L > R) break;
    mid = L + R >> 1;
    A = mid / x;
    B = mid / y;
    A_B = mid / (x * y);
    LAS = mid - (A + B - A_B);
    Ra = A - A_B;
    Rb = B - A_B;
    cnt1 -= Rb;
    cnt2 -= Ra;
    if (cnt1 > 0 && cnt2 > 0) {
      if (cnt1 + cnt2 > LAS)
        L = mid + 1;
      else
        R = mid - 1, ans = mid;
      cnt1 = q;
      cnt2 = p;
      continue;
    }
    if (cnt1 > 0 && cnt2 <= 0) {
      if (cnt1 - LAS > 0)
        L = mid + 1;
      else
        R = mid - 1, ans = mid;
      cnt1 = q;
      cnt2 = p;
      continue;
    }
    if (cnt1 <= 0 && cnt2 > 0) {
      if (cnt2 - LAS > 0)
        L = mid + 1;
      else
        R = mid - 1, ans = mid;
      cnt1 = q;
      cnt2 = p;
      continue;
    }
    if (cnt1 <= 0 && cnt2 <= 0) {
      ans = mid, R = mid - 1;
      cnt1 = q;
      cnt2 = p;
      continue;
    }
    L = mid + 1;
    cnt1 = q;
    cnt2 = p;
  }
  cout << ans;
  return 0;
}
