#include <bits/stdc++.h>
using namespace std;
long long fun(long long x, long long y, long long cnt1, long long cnt2) {
  long long z = x * y;
  long long l = 1, r = (1000000000000000000 + 5), mid;
  while (1) {
    mid = (l + r) / 2;
    if (mid - mid / x == cnt1)
      break;
    else if (mid - mid / x < cnt1)
      l = mid;
    else
      r = mid;
  }
  while (mid - mid / x == cnt1) mid--;
  long long n1 = mid + 1;
  long long n2 = n1 / x - n1 / z;
  long long n3 = cnt2 - n2;
  if (n3 <= 0) return n1;
  l = 1;
  r = (1000000000000000000 + 5);
  while (1) {
    mid = (l + r) / 2;
    long long t = mid - n1 - (mid / y - n1 / y);
    if (t == n3)
      break;
    else if (t < n3)
      l = mid;
    else
      r = mid;
  }
  while (mid - n1 - (mid / y - n1 / y) == n3) mid--;
  return mid + 1;
}
int main() {
  long long c1, c2, x, y;
  cin >> c1 >> c2 >> x >> y;
  fun(x, y, c1, c2);
  cout << min(fun(x, y, c1, c2), fun(y, x, c2, c1)) << endl;
}
