#include <bits/stdc++.h>
using namespace std;
int main() {
  long long cnt1, cnt2, x, y;
  while (scanf("%lld%lld%lld%lld", &cnt1, &cnt2, &x, &y) != EOF) {
    long long num1, num2;
    if (x - 1 > 1) {
      if (cnt1 % x == 0)
        num1 = 1 + ((cnt1 - 1) / (x - 1)) * x;
      else
        num1 = cnt1 % x + ((cnt1 - 1) / (x - 1)) * x;
    } else
      num1 = 1 + (cnt1 - 1) * x;
    if (y - 1 > 1) {
      if (cnt2 % y == 0)
        num2 = 1 + ((cnt2 - 1) / (y - 1)) * y;
      else
        num2 = cnt2 % y + ((cnt1 - 1) / (y - 1)) * y;
    } else
      num2 = 1 + (cnt2 - 1) * y;
    long long maxx;
    if (num1 > num2)
      maxx = num1;
    else if (num1 < num2)
      maxx = num2;
    else if (num1 == num2)
      maxx = min(num1 + x - 1, num2 + y - 1);
    printf("%lld\n", maxx);
  }
  return 0;
}
