#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 220000;
int arr[N];
int n, m, r, g;
long long cnt1, cnt2, x, y;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
bool ok(long long target) {
  long long total = target;
  long long temp = x * y / gcd(x, y);
  total -= (target / temp);
  long long temp1 = total - (target / x - target / temp);
  long long temp2 = total - (target / y - target / temp);
  return temp1 >= cnt1 && temp2 >= cnt2;
}
int main() {
  while (cin >> cnt1 >> cnt2 >> x >> y) {
    long long l = 0;
    long long r = 1e15;
    while (l < r) {
      long long mid = (l + r) / 2;
      if (ok(mid))
        r = mid;
      else
        l = mid + 1;
    }
    cout << l << endl;
  }
  return 0;
}
