#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, x, y, ans1, ans2, xx;
  cin >> a >> b >> x >> y;
  xx = a / (x - 1);
  if (a % (x - 1) == 0) {
    ans1 = x * xx - 1;
  } else {
    ans1 = x * xx + (a % (x - 1));
  }
  xx = b / (y - 1);
  if (b % (y - 1) == 0) {
    ans2 = y * xx - 1;
  } else {
    ans2 = y * xx + (b % (y - 1));
  }
  if (ans1 > ans2)
    cout << ans1;
  else
    cout << ans2;
  return 0;
}
