#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e6 + 13;
const long long INFL = 9223372036854775807;
const int INF = 2147483647;
const long long MOD = (int)1e9 + 93, MOD2 = 1e9 + 21;
const long long base = 101, base2 = 37;
const long double pi = 3.1415926535897932;
long long f(long long m, long long x, long long y) {
  return m - m / x - m / y + m / (x * y);
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  ;
  long long cnt1, cnt2, x, y;
  cin >> cnt1 >> cnt2 >> x >> y;
  long long l = 0, r = 1e18;
  while (r - l > 1) {
    long long m = (l + r) / 2;
    long long ox = (m / x - m / (x * y));
    long long oy = (m / y - m / (x * y));
    if (f(m, x, y) >= max(0ll, cnt1 - oy) + max(0ll, cnt2 - ox))
      r = m;
    else
      l = m;
  }
  cout << r << "\n";
  return 0;
}
