#include <bits/stdc++.h>
using namespace std;
int max(int a, int b, int c) {
  if (a < b) a = b;
  if (a < c) a = c;
  return a;
}
int main() {
  int n1, n2, p1, p2;
  cin >> n1 >> n2 >> p1 >> p2;
  int a = 0, b = 0, c = 0;
  a = n1 + n2 + (n1 + n2) / (p1 * p2);
  a += a / (p1 * p2) - (n1 + n2) / (p1 * p2);
  b = (n1 / (p1 - 1)) * p1 + n1 % (p1 - 1);
  if (n1 % (p1 - 1) == 0) b--;
  c = (n2 / (p2 - 1)) * p2 + n2 % (p2 - 1);
  if (n2 % (p2 - 1) == 0) c--;
  cout << max(a, b, c);
}
