#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T a) {
  return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
  return a * a;
}
const int N = 100009;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long long INF64 = 1e18;
const long double PI = 3.1415926535897932384626433832795;
int cnt1, cnt2, x, y;
bool read() {
  if (!(cin >> cnt1 >> cnt2 >> x >> y)) return false;
  return true;
}
bool f(long long z) {
  if (z - z / x < cnt1) return false;
  if (z - z / y - max(0LL, cnt1 - z / y + z / (x * y)) < cnt2) return false;
  return true;
}
void solve() {
  long long l = 1, r = 1e18;
  while (r - l > 1) {
    long long m = (l + r) / 2;
    if (f(m))
      r = m;
    else
      l = m;
  }
  for (int i = l; i <= r; ++i)
    if (f(i)) {
      cout << i;
      return;
    }
}
int main() {
  srand(time(NULL));
  cout << setprecision(10) << fixed;
  while (read()) solve();
  return 0;
}
