#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, v;
bool can(long long size) {
  long long a, b, c, d;
  a = size / x;
  b = size / (x * y);
  c = size / y;
  d = size - a - c + b;
  long long x1 = size - a;
  long long y1 = size - c;
  if (x1 + y1 - d >= n + m && x1 >= n && y1 >= m) return true;
  return false;
}
int main() {
  scanf("%I64d %I64d %I64d %I64d", &n, &m, &x, &y);
  long long low = n + m;
  long long high = 1000000000;
  while (high >= low) {
    int mid = (low + high) >> 1;
    if (can(mid)) {
      v = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }
  printf("%I64d\n", v);
  return 0;
}
