#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:300000000")
#pragma warning(disable : 4996)
using namespace std;
long long int cnt1, cnt2, x, y;
bool check(long long int a) {
  int a1 = a / x;
  int a2 = a / y;
  int a3 = a / (x * y);
  a -= a3;
  a1 -= a3;
  a2 -= a3;
  if (a - a1 >= cnt1 && a - a2 >= cnt2 && a >= cnt1 + cnt2)
    return true;
  else
    return false;
}
long long int bin_search(long long int l, long long int r) {
  while (l < r) {
    unsigned long long int mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> cnt1 >> cnt2 >> x >> y;
  cout << bin_search(1ull, 1000000000000ull) << endl;
  return 0;
}
