#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d, l = 0, r = 2147483647, o;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  while (l < r) {
    o = (long long)l + r >> 1;
    if (o - o / c / d >= a + b && o - o / c >= a && o - o / d >= b)
      r = o;
    else
      l = o + 1;
  }
  printf("%d\n", l);
}
