#include <bits/stdc++.h>
using namespace std;
long long c1, c2;
int x, y;
bool can(long long v) {
  long long a = v - v / x;
  long long b = v - v / y;
  long long c = v - v / (x * y);
  if (a >= c1 && b >= c2 && c >= c1 + c2) return true;
  return false;
}
int main() {
  scanf("%I64d %I64d %d %d", &c1, &c2, &x, &y);
  long long l = 2, u = 1e10;
  long long ans;
  while (l <= u) {
    long long m = (l + u) / 2;
    if (can(m)) {
      ans = m;
      u = m - 1;
    } else
      l = m + 1;
  }
  printf("%I64d\n", ans);
}
