#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) return a;
  return (a % b == 0 ? b : gcd(b, a % b));
}
int main() {
  long long i, j, k, m, n, t, test = 1, ans, r, c1, c2, x, y, f, c;
  t = 1;
  while (t--) {
    scanf("%I64d", &c1);
    scanf("%I64d", &c2);
    scanf("%I64d", &x);
    scanf("%I64d", &y);
    c = c1 + c2;
    i = c / x;
    j = c / y;
    if (c1 < j) {
      k = (j - c1);
      for (t = 0; t < k; t++) {
        c++;
        if (c % y == 0) {
          c++;
        }
      }
    }
    if (c2 < i) {
      k = (i - c2);
      for (t = 0; t < k; t++) {
        c++;
        if (c % x == 0) {
          c++;
        }
      }
    }
    printf("%I64d\n", c);
    t = 0;
  }
  return 0;
}
