#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
const long long MOD = 1000000007;
const long long FMOD = 998244353;
long long cnt1, cnt2, x, y;
bool isSafe(long long mid) {
  long long div1 = mid / x;
  long long div2 = mid / y;
  long long div3 = mid / (x * y);
  long long no = mid - (div1 + div2 - div3);
  long long p = div1 - div3;
  long long q = div2 - div3;
  long long ans1 = cnt1 - q;
  long long ans2 = cnt2 - p;
  if (ans1 < 0) ans1 = 0;
  if (ans2 < 0) ans2 = 0;
  return (ans1 + ans2) <= no;
}
signed main() {
  cin >> cnt1 >> cnt2 >> x >> y;
  long long beg = 0, end = 1e10;
  long long ans = 0;
  while (beg <= end) {
    long long mid = (beg + end) / 2;
    if (isSafe(mid)) {
      ans = mid;
      end = mid - 1;
    } else {
      beg = mid + 1;
    }
  }
  cout << ans;
}
