#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(false);
  register int A, B, X, Y;
  cin >> A >> B >> X >> Y;
  cout << floor(max(
              1.0 * (A + B - 1) / (X * Y - 1) * X * Y,
              max(1.0 * (A - 1) / (X - 1) * X, 1.0 * (B - 1) / (Y - 1) * Y))) +
              1
       << endl;
  return 0;
}
