#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T getNext() {
  T s = 1, x = 0, c = getc(stdin);
  while (c <= 32) c = getc(stdin);
  if (c == '-') s = -1, c = getc(stdin);
  while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getc(stdin);
  return x * s;
}
const double eps = 1e-9;
bool Equals(double x, double y) { return abs(x - y) < eps; }
bool Less(double x, double y) { return (x) < y - eps; }
bool LessOrEqual(double x, double y) { return (x) < y + eps; }
const int MaxN = int(1e5) + 256;
int get(int cnt1, int cnt2, int x, int y) {
  int first = (cnt1 * x - 1) / (x - 1);
  int second = first / x;
  int s1 = second;
  if (second >= cnt2) return max(first, second);
  second = ((cnt2 - s1) * y - 1) / (y - 1) + first;
  second += (second % y == 0);
  return max(first, second);
}
int main() {
  int cnt1 = getNext<int>(), cnt2 = getNext<int>(), x = getNext<int>(),
      y = getNext<int>();
  cout << min(get(cnt1, cnt2, x, y), get(cnt2, cnt1, y, x));
  return 0;
}
