#include <bits/stdc++.h>
int main() {
  int x, y, ca, cb;
  scanf("%d %d %d %d", &ca, &cb, &x, &y);
  long long int r = 10000000000, v;
  long long int l = 1;
  int f = 0;
  long long ans = -1;
  while (l <= r) {
    v = (r + l) / 2;
    f = 0;
    if (ca > cb) {
      long long int t1 = v - v / x;
      long int t2 = v - v / y - (ca - v / y + v / (x * y));
      if (t1 >= ca && t2 >= cb) f = 1;
    } else {
      long long int t2 = v - v / y;
      long long int t1 = v - v / x - (cb - v / x + v / (x * y));
      if (t1 >= ca && t2 >= cb) f = 1;
    }
    if (f == 1) {
      ans = v;
      r = v - 1;
    } else
      l = v + 1;
  }
  printf("%Ld\n", ans);
  return 0;
}
