#include <bits/stdc++.h>
using namespace std;
long long cnt1, cnt2, x, y;
const long long inf = 2e9;
long long g(long long a, long long b) {
  if (b == 0) return a;
  return g(b, a % b);
}
long long l(long long a, long long b) { return a * b / g(a, b); }
bool f(long long v) {
  long long temp = (v / l(x, y));
  temp = v - temp;
  return ((v - (v / x) >= cnt1) and (v - (v / y) >= cnt2) and
          temp >= cnt1 + cnt2);
}
long long binarySearch(long long st, long long end) {
  while (st + 1 < end) {
    long long mid = (st + end) / 2;
    if (f(mid)) {
      end = mid;
    } else {
      st = mid;
    }
  }
  if (f(st)) return st;
  return end;
}
int main() {
  cin >> cnt1 >> cnt2 >> x >> y;
  long long ans = binarySearch(1, inf);
  cout << ans << endl;
  return 0;
}
