#include <bits/stdc++.h>
using namespace std;
int main() {
  int c1, c2, x, y;
  cin >> c1 >> c2 >> x >> y;
  int v = (c1 + c2);
  int N, B, a, b;
  b = v / x;
  a = v / y;
  N = v / (x * y);
  a = a - N;
  b = b - N;
  B = v - (N + a + b);
  if (((c1 > a ? (c1 - a) : 0) + (c2 > b ? (c2 - b) : 0)) == B) {
    cout << v;
    return 0;
  }
  while (((c1 > a ? (c1 - a) : 0) + (c2 > b ? (c2 - b) : 0)) > B) {
    v = v * 2;
    b = v / x;
    a = v / y;
    N = v / (x * y);
    a = a - N;
    b = b - N;
    B = v - (N + a + b);
  }
  int l = v / 2, t = 10;
  int mid;
  while (t--) {
    mid = l + (v - l) / 2;
    b = mid / x;
    a = mid / y;
    N = mid / (x * y);
    a = a - N;
    b = b - N;
    B = mid - (N + a + b);
    if (((c1 > a ? (c1 - a) : 0) + (c2 > b ? (c2 - b) : 0)) == B) {
      cout << mid;
      return 0;
    } else if (((c1 > a ? (c1 - a) : 0) + (c2 > b ? (c2 - b) : 0)) < B)
      v = mid;
    else
      l = mid;
  }
}
