#include <bits/stdc++.h>
using namespace std;
long long int cnt1, cnt2, x, y;
long long int f(long long int k) {
  long long int d1 = k / x;
  long long int d2 = k / y;
  long long int c = k / (x * y);
  long long int count1 = 0, count2 = 0;
  long long int rem = k - d1 - d2 + c;
  d1 = d1 - c;
  d2 = d2 - c;
  count1 += d2;
  count2 += d1;
  if (count1 < cnt1) {
    rem = rem - (cnt1 - count1);
    if (rem < 0) return 0;
  }
  if (count2 < cnt2) {
    rem = rem - (cnt2 - count2);
    if (rem < 0) return 0;
  }
  return 1;
}
int main() {
  long long int st, ed, mid;
  cin >> cnt1 >> cnt2 >> x >> y;
  st = 1;
  ed = 1e18;
  while (ed - st > 1) {
    mid = (st + ed) >> 1;
    if (f(mid)) {
      ed = mid;
    } else {
      st = mid;
    }
  }
  cout << ed << endl;
  return 0;
}
