#include <bits/stdc++.h>
using namespace std;
int x, y, c1, c2;
bool ok(int n) {
  int a, b, c, rest;
  a = n / x;
  b = n / y;
  c = n / (x + y);
  rest = n - (a + b) + c;
  a -= c;
  b -= c;
  int need[] = {c1 - b, c2 - a};
  if (need[0] < 0) need[0] = 0;
  if (need[1] < 0) need[1] = 0;
  return (need[0] + need[1]) <= rest;
}
int main() {
  cin >> c1 >> c2 >> x >> y;
  int l = 0, r = 1e9 + 1, md;
  while (l < r) {
    md = (l + r) / 2;
    if (ok(md))
      r = md;
    else
      l = md + 1;
  }
  cout << r;
  return 0;
}
