#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e9 + 7;
const long long MOD = 1e9 + 7;
long long cnt1, cnt2, x, y;
bool check(long long n) {
  long long all = n - n / x - n / y + n / (x * y);
  long long f1 = n / x - n / (x * y);
  long long f2 = n / y - n / (x * y);
  long long g1 = max(cnt1 - f2, 0ll);
  long long g2 = max(cnt2 - f1, 0ll);
  return (g1 + g2 <= all);
}
signed main() {
  cin >> cnt1 >> cnt2 >> x >> y;
  long long l = 0, r = 2e9;
  long long mid = (l + r) / 2;
  while (l != mid && r != mid) {
    if (check(mid)) {
      r = mid;
    } else
      l = mid + 1;
    mid = (l + r) / 2;
  }
  if (check(l)) {
    cout << l;
  } else {
    cout << r;
  }
  return 0;
}
