#include <bits/stdc++.h>
using namespace std;
long long cnt1, cnt2, x, y, k;
bool check(long long z) {
  long long a = z / x, b = z / y, c = z / (x * y), d, j = 0, f = cnt1;
  d = z - a - b + c;
  if (cnt1 <= b - c)
    j = 1;
  else if (cnt1 <= b - c + d && cnt1 >= b - c) {
    f = f - b + c;
    d = d - f;
    j = 1;
  }
  if (cnt2 <= a - c + d && j == 1)
    return true;
  else
    return false;
}
void bs(long long s, long long e) {
  if (e - s <= 1) {
    if (check(s) == true)
      k = s;
    else if (check(e) == true)
      k = e;
    return;
  }
  long long m = (e + s) / 2;
  if (check(m) == true) {
    k = m;
    bs(s, m);
  } else
    bs(m, e);
}
int main() {
  cin >> cnt1 >> cnt2 >> x >> y;
  long long big = 1000 * 1000 * 1000 * 10;
  bs(1, big);
  cout << k << endl;
  return 0;
}
